webpack.plugin.config.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. const path = require('path')
  2. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  3. const bundleAnalyzer = new BundleAnalyzerPlugin({
  4. analyzerPort: 0,
  5. })
  6. module.exports = options => {
  7. const isDev = !!process.env.TERMINUS_DEV
  8. const devtool = isDev && process.platform === 'win32' ? 'eval-cheap-module-source-map' : 'cheap-module-source-map'
  9. const config = {
  10. target: 'node',
  11. entry: 'src/index.ts',
  12. context: options.dirname,
  13. devtool,
  14. output: {
  15. path: path.resolve(options.dirname, 'dist'),
  16. filename: 'index.js',
  17. pathinfo: true,
  18. libraryTarget: 'umd',
  19. devtoolModuleFilenameTemplate: `webpack-terminus-${options.name}:///[resource-path]`,
  20. },
  21. mode: isDev ? 'development' : 'production',
  22. optimization:{
  23. minimize: false,
  24. },
  25. cache: !isDev ? false : {
  26. type: 'filesystem',
  27. cacheDirectory: path.resolve(options.dirname, 'node_modules', '.webpack-cache'),
  28. },
  29. resolve: {
  30. modules: ['.', 'src', 'node_modules', '../app/node_modules'].map(x => path.join(options.dirname, x)),
  31. extensions: ['.ts', '.js'],
  32. },
  33. module: {
  34. rules: [
  35. {
  36. test: /\.ts$/,
  37. use: {
  38. loader: 'awesome-typescript-loader',
  39. options: {
  40. configFileName: path.resolve(options.dirname, 'tsconfig.json'),
  41. typeRoots: [
  42. path.resolve(options.dirname, 'node_modules/@types'),
  43. path.resolve(options.dirname, '../node_modules/@types'),
  44. ],
  45. paths: {
  46. 'terminus-*': [path.resolve(options.dirname, '../terminus-*')],
  47. '*': [
  48. path.resolve(options.dirname, '../app/node_modules/*'),
  49. path.resolve(options.dirname, '../node_modules/*'),
  50. ],
  51. },
  52. },
  53. },
  54. },
  55. { test: /\.pug$/, use: ['apply-loader', 'pug-loader'] },
  56. { test: /\.scss$/, use: ['@terminus-term/to-string-loader', 'css-loader', 'sass-loader'] },
  57. { test: /\.css$/, use: ['@terminus-term/to-string-loader', 'css-loader'], include: /component\.css/ },
  58. { test: /\.css$/, use: ['style-loader', 'css-loader'], exclude: /component\.css/ },
  59. { test: /\.yaml$/, use: ['json-loader', 'yaml-loader'] },
  60. { test: /\.svg/, use: ['svg-inline-loader'] },
  61. {
  62. test: /\.(ttf|eot|otf|woff|woff2|ogg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
  63. use: {
  64. loader: 'url-loader',
  65. options: {
  66. limit: 999999999999,
  67. },
  68. },
  69. },
  70. ],
  71. },
  72. externals: [
  73. 'any-promise',
  74. 'child_process',
  75. 'electron-promise-ipc',
  76. 'electron',
  77. 'fontmanager-redux',
  78. 'fs',
  79. 'keytar',
  80. 'macos-native-processlist',
  81. 'native-process-working-directory',
  82. 'net',
  83. 'ngx-toastr',
  84. 'os',
  85. 'path',
  86. 'readline',
  87. 'serialport',
  88. 'socksv5',
  89. 'stream',
  90. 'windows-native-registry',
  91. 'windows-process-tree',
  92. 'windows-process-tree/build/Release/windows_process_tree.node',
  93. 'yargs/yargs',
  94. /^@angular/,
  95. /^@ng-bootstrap/,
  96. /^rxjs/,
  97. /^terminus-/,
  98. ...options.externals || [],
  99. ],
  100. plugins: [],
  101. }
  102. if (process.env.PLUGIN_BUNDLE_ANALYZER === options.name) {
  103. config.plugins.push(bundleAnalyzer)
  104. }
  105. return config
  106. }