webpack.config.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. useCache: true,
  47. forceIsolatedModules: true
  48. }
  49. }
  50. ]
  51. },
  52. resolve: {
  53. extensions: ['.ts']
  54. },
  55. plugins: [
  56. new webpack.BannerPlugin(
  57. {
  58. banner: getBannerText(),
  59. raw: true,
  60. entryOnly: false
  61. }
  62. ),
  63. new CheckerPlugin(),
  64. new TSLintPlugin({
  65. files: ['./src/**/*.ts'],
  66. project: './tsconfig.json',
  67. exclude: []
  68. })
  69. ],
  70. output: {
  71. libraryTarget: "commonjs2",
  72. library: "JavaScriptObfuscator"
  73. },
  74. stats: {
  75. maxModules: 0
  76. }
  77. };