webpack.plugin.config.js 4.6 KB

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