webpack.plugin.config.js 4.3 KB

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