webpack.config.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. 'use strict';
  2. const fs = require("fs");
  3. const nodeExternals = require('webpack-node-externals');
  4. const webpack = require('webpack');
  5. const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
  6. /**
  7. * @return {string}
  8. */
  9. const getLicenseText = () => {
  10. return "/*\nCopyright (C) 2017 Timofey Kachalov <[email protected]>\n\n" +
  11. fs.readFileSync('./LICENSE.BSD', 'utf8') + "\n*/";
  12. };
  13. /**
  14. * @return {string}
  15. */
  16. const getSourceMapSupportImport = () => {
  17. return `require("source-map-support").install();`;
  18. };
  19. /**
  20. * @return {string}
  21. */
  22. const getBannerText = () => {
  23. const lineSeparator = '\n\n';
  24. return getLicenseText() +
  25. lineSeparator +
  26. getSourceMapSupportImport() +
  27. lineSeparator;
  28. };
  29. module.exports = {
  30. entry: {
  31. 'index': './index.ts'
  32. },
  33. cache: true,
  34. devtool: 'source-map',
  35. target: 'node',
  36. externals: [nodeExternals()],
  37. module: {
  38. rules: [
  39. {
  40. enforce: 'pre',
  41. test: /\.ts(x?)$/,
  42. loader: 'tslint-loader',
  43. exclude: /(node_modules)/
  44. },
  45. {
  46. test: /\.ts(x?)$/,
  47. loader: 'awesome-typescript-loader',
  48. query: {
  49. useBabel: true,
  50. useCache: true
  51. }
  52. }
  53. ]
  54. },
  55. resolve: {
  56. extensions: ['.ts']
  57. },
  58. plugins: [
  59. new webpack.BannerPlugin(
  60. {
  61. banner: getBannerText(),
  62. raw: true,
  63. entryOnly: false
  64. }
  65. ),
  66. new CheckerPlugin()
  67. ],
  68. output: {
  69. path: __dirname + '/dist',
  70. filename: '[name].js',
  71. libraryTarget: "commonjs2",
  72. library: "JavaScriptObfuscator"
  73. },
  74. stats: {
  75. maxModules: 0
  76. }
  77. };