webpack.config.js 2.0 KB

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