webpack.config.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. rules: [
  40. {
  41. enforce: 'pre',
  42. test: /\.ts(x?)$/,
  43. loader: 'tslint-loader',
  44. exclude: /(node_modules)/
  45. },
  46. {
  47. test: /\.ts(x?)$/,
  48. loader: 'awesome-typescript-loader',
  49. query: {
  50. useBabel: true,
  51. useCache: true
  52. }
  53. }
  54. ]
  55. },
  56. resolve: {
  57. extensions: ['.ts']
  58. },
  59. plugins: [
  60. new webpack.BannerPlugin(
  61. {
  62. banner: getBannerText(),
  63. raw: true,
  64. entryOnly: false
  65. }
  66. ),
  67. new CheckerPlugin()
  68. ],
  69. output: {
  70. path: __dirname + '/dist',
  71. filename: '[name].js',
  72. libraryTarget: "commonjs2",
  73. library: "JavaScriptObfuscator"
  74. },
  75. stats: {
  76. maxModules: 0
  77. }
  78. };