webpack.config.js 1.9 KB

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