|
| 1 | +import path from 'path'; |
| 2 | +import webpack from 'webpack'; |
| 3 | +import { merge } from 'webpack-merge'; |
| 4 | +import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; |
| 5 | +import baseConfig from './webpack.config.base'; |
| 6 | +import webpackPaths from './webpack.paths'; |
| 7 | +import checkNodeEnv from '../scripts/check-node-env'; |
| 8 | + |
| 9 | +// When an ESLint server is running, we can't set the NODE_ENV so we'll check if it's |
| 10 | +// at the dev webpack config is not accidentally run in a production environment |
| 11 | +if (process.env.NODE_ENV === 'production') { |
| 12 | + checkNodeEnv('development'); |
| 13 | +} |
| 14 | + |
| 15 | +const configuration: webpack.Configuration = { |
| 16 | + devtool: 'inline-source-map', |
| 17 | + |
| 18 | + mode: 'development', |
| 19 | + |
| 20 | + target: 'electron-preload', |
| 21 | + |
| 22 | + entry: path.join(webpackPaths.srcMainPath, 'preload.ts'), |
| 23 | + |
| 24 | + output: { |
| 25 | + path: webpackPaths.dllPath, |
| 26 | + filename: 'preload.js', |
| 27 | + library: { |
| 28 | + type: 'umd', |
| 29 | + }, |
| 30 | + }, |
| 31 | + |
| 32 | + plugins: [ |
| 33 | + new BundleAnalyzerPlugin({ |
| 34 | + analyzerMode: process.env.ANALYZE === 'true' ? 'server' : 'disabled', |
| 35 | + }), |
| 36 | + |
| 37 | + /** |
| 38 | + * Create global constants which can be configured at compile time. |
| 39 | + * |
| 40 | + * Useful for allowing different behaviour between development builds and |
| 41 | + * release builds |
| 42 | + * |
| 43 | + * NODE_ENV should be production so that modules do not perform certain |
| 44 | + * development checks |
| 45 | + * |
| 46 | + * By default, use 'development' as NODE_ENV. This can be overriden with |
| 47 | + * 'staging', for example, by changing the ENV variables in the npm scripts |
| 48 | + */ |
| 49 | + new webpack.EnvironmentPlugin({ |
| 50 | + NODE_ENV: 'development', |
| 51 | + }), |
| 52 | + |
| 53 | + new webpack.LoaderOptionsPlugin({ |
| 54 | + debug: true, |
| 55 | + }), |
| 56 | + ], |
| 57 | + |
| 58 | + /** |
| 59 | + * Disables webpack processing of __dirname and __filename. |
| 60 | + * If you run the bundle in node.js it falls back to these values of node.js. |
| 61 | + * https://github.com/webpack/webpack/issues/2010 |
| 62 | + */ |
| 63 | + node: { |
| 64 | + __dirname: false, |
| 65 | + __filename: false, |
| 66 | + }, |
| 67 | + |
| 68 | + watch: true, |
| 69 | +}; |
| 70 | + |
| 71 | +export default merge(baseConfig, configuration); |
0 commit comments