|
| 1 | +/** |
| 2 | + * Webpack config for production electron main process |
| 3 | + */ |
| 4 | + |
| 5 | +import path from 'path'; |
| 6 | +import webpack from 'webpack'; |
| 7 | +import { merge } from 'webpack-merge'; |
| 8 | +import TerserPlugin from 'terser-webpack-plugin'; |
| 9 | +import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; |
| 10 | +import baseConfig from './webpack.config.base'; |
| 11 | +import webpackPaths from './webpack.paths'; |
| 12 | +import checkNodeEnv from '../scripts/check-node-env'; |
| 13 | +import deleteSourceMaps from '../scripts/delete-source-maps'; |
| 14 | +import { prodMainCopyPlugins, moduleRules } from './copy-plugin' |
| 15 | + |
| 16 | +checkNodeEnv('production'); |
| 17 | +deleteSourceMaps(); |
| 18 | + |
| 19 | +const configuration: webpack.Configuration = { |
| 20 | + devtool: false, |
| 21 | + // module: {...moduleRules}, |
| 22 | + mode: 'production', |
| 23 | + |
| 24 | + target: 'electron-main', |
| 25 | + |
| 26 | + entry: { |
| 27 | + main: path.join(webpackPaths.srcMainPath, 'main.ts'), |
| 28 | + preload: path.join(webpackPaths.srcMainPath, 'preload.ts'), |
| 29 | + }, |
| 30 | + |
| 31 | + output: { |
| 32 | + path: webpackPaths.distMainPath, |
| 33 | + filename: '[name].js', |
| 34 | + library: { |
| 35 | + type: 'umd', |
| 36 | + }, |
| 37 | + }, |
| 38 | + |
| 39 | + optimization: { |
| 40 | + minimizer: [ |
| 41 | + new TerserPlugin({ |
| 42 | + parallel: true, |
| 43 | + }), |
| 44 | + ], |
| 45 | + }, |
| 46 | + |
| 47 | + plugins: [ |
| 48 | + ...prodMainCopyPlugins, |
| 49 | + new BundleAnalyzerPlugin({ |
| 50 | + analyzerMode: process.env.ANALYZE === 'true' ? 'server' : 'disabled', |
| 51 | + analyzerPort: 8888, |
| 52 | + }), |
| 53 | + |
| 54 | + /** |
| 55 | + * Create global constants which can be configured at compile time. |
| 56 | + * |
| 57 | + * Useful for allowing different behaviour between development builds and |
| 58 | + * release builds |
| 59 | + * |
| 60 | + * NODE_ENV should be production so that modules do not perform certain |
| 61 | + * development checks |
| 62 | + */ |
| 63 | + // @ts-ignore |
| 64 | + new webpack.EnvironmentPlugin({ |
| 65 | + NODE_ENV: 'production', |
| 66 | + DEBUG_PROD: false, |
| 67 | + START_MINIMIZED: false, |
| 68 | + }), |
| 69 | + |
| 70 | + new webpack.DefinePlugin({ |
| 71 | + 'process.type': '"browser"', |
| 72 | + }), |
| 73 | + ], |
| 74 | + |
| 75 | + /** |
| 76 | + * Disables webpack processing of __dirname and __filename. |
| 77 | + * If you run the bundle in node.js it falls back to these values of node.js. |
| 78 | + * https://github.com/webpack/webpack/issues/2010 |
| 79 | + */ |
| 80 | + node: { |
| 81 | + __dirname: false, |
| 82 | + __filename: false, |
| 83 | + }, |
| 84 | +}; |
| 85 | + |
| 86 | +export default merge(baseConfig, configuration); |
0 commit comments