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 TSLintPlugin = require('tslint-webpack-plugin');
  7. const copyright = 'Copyright (C) 2017 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. })
  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. };