webpack.plugin.config.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. publicPath: 'auto',
  28. },
  29. mode: isDev ? 'development' : 'production',
  30. optimization:{
  31. minimize: false,
  32. },
  33. cache: !isDev ? false : {
  34. type: 'filesystem',
  35. cacheDirectory: path.resolve(options.dirname, 'node_modules', '.webpack-cache'),
  36. },
  37. resolve: {
  38. modules: ['.', 'src', 'node_modules', '../app/node_modules'].map(x => path.join(options.dirname, x)),
  39. extensions: ['.ts', '.js'],
  40. },
  41. module: {
  42. rules: [
  43. ...options.rules ?? [],
  44. {
  45. test: /\.ts$/,
  46. use: {
  47. loader: 'awesome-typescript-loader',
  48. options: {
  49. configFileName: path.resolve(options.dirname, 'tsconfig.json'),
  50. typeRoots: [
  51. path.resolve(options.dirname, 'node_modules/@types'),
  52. path.resolve(options.dirname, '../node_modules/@types'),
  53. ],
  54. paths: {
  55. 'terminus-*': [path.resolve(options.dirname, '../terminus-*')],
  56. '*': [
  57. path.resolve(options.dirname, '../app/node_modules/*'),
  58. path.resolve(options.dirname, '../node_modules/*'),
  59. ],
  60. },
  61. },
  62. },
  63. },
  64. { test: /\.pug$/, use: ['apply-loader', 'pug-loader'] },
  65. { test: /\.scss$/, use: ['@terminus-term/to-string-loader', 'css-loader', 'sass-loader'], include: /(theme.*|component)\.scss/ },
  66. { test: /\.scss$/, use: ['style-loader', 'css-loader', 'sass-loader'], exclude: /(theme.*|component)\.scss/ },
  67. { test: /\.css$/, use: ['@terminus-term/to-string-loader', 'css-loader'], include: /component\.css/ },
  68. { test: /\.css$/, use: ['style-loader', 'css-loader'], exclude: /component\.css/ },
  69. { test: /\.yaml$/, use: ['json-loader', 'yaml-loader'] },
  70. { test: /\.svg/, use: ['svg-inline-loader'] },
  71. {
  72. test: /\.(ttf|eot|otf|woff|woff2|ogg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
  73. use: {
  74. loader: 'url-loader',
  75. options: {
  76. limit: 999999999999,
  77. },
  78. },
  79. },
  80. ],
  81. },
  82. externals: [
  83. '@electron/remote',
  84. 'any-promise',
  85. 'child_process',
  86. 'electron-promise-ipc',
  87. 'electron',
  88. 'fontmanager-redux',
  89. 'fs',
  90. 'keytar',
  91. 'macos-native-processlist',
  92. 'native-process-working-directory',
  93. 'net',
  94. 'ngx-toastr',
  95. 'os',
  96. 'path',
  97. 'readline',
  98. 'serialport',
  99. 'ssh2',
  100. 'ssh2/lib/protocol/constants',
  101. 'socksv5',
  102. 'stream',
  103. 'windows-native-registry',
  104. 'windows-process-tree',
  105. 'windows-process-tree/build/Release/windows_process_tree.node',
  106. /^@angular/,
  107. /^@ng-bootstrap/,
  108. /^rxjs/,
  109. /^terminus-/,
  110. ...options.externals || [],
  111. ],
  112. plugins: [
  113. new webpack.SourceMapDevToolPlugin(sourceMapOptions),
  114. ],
  115. }
  116. if (process.env.PLUGIN_BUNDLE_ANALYZER === options.name) {
  117. config.plugins.push(bundleAnalyzer)
  118. }
  119. return config
  120. }