webpack.config.js 1.9 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 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. devtool: 'source-map',
  36. target: 'node',
  37. externals: [nodeExternals()],
  38. module: {
  39. exprContextCritical: false,
  40. rules: [
  41. {
  42. test: /\.ts(x?)$/,
  43. loader: 'awesome-typescript-loader',
  44. query: {
  45. useBabel: true,
  46. babelCore: '@babel/core',
  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. libraryTarget: "commonjs2",
  73. library: "JavaScriptObfuscator"
  74. },
  75. stats: {
  76. maxModules: 0
  77. }
  78. };