-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathwebpack.main.prod.js
118 lines (113 loc) · 3.16 KB
/
webpack.main.prod.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* Webpack config for production electron main process
*/
import path from 'path';
import webpack from 'webpack';
import {
BundleAnalyzerPlugin,
} from 'webpack-bundle-analyzer';
module.exports = () => ({
mode: 'production',
devtool: 'source-map',
target: 'electron-main',
entry: path.join(__dirname, 'app/main/index.js'),
output: {
path: path.resolve(__dirname, 'app/dist'),
filename: 'main.prod.js',
},
resolve: {
extensions: ['.js', '.jsx', '.mjs', '.wasm', '.json'],
alias: {
shared: path.resolve(__dirname, 'app/shared'),
},
},
plugins: [
/**
* Create global constants which can be configured at compile time.
*
* Useful for allowing different behaviour between development builds and
* release builds
*
* NODE_ENV should be production so that modules do not perform certain
* development checks
*/
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production'),
'process.env.BABEL_ENV': JSON.stringify(process.env.BABEL_ENV || 'production'),
'process.env.DEBUG_PROD': JSON.stringify(process.env.DEBUG_PROD || 'false'),
'process.env.SENTRY_DSN': JSON.stringify(process.env.SENTRY_DSN),
}),
new BundleAnalyzerPlugin({
analyzerMode: 'static',
}),
],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
babelrc: false,
cacheDirectory: false,
presets: [
[
'@babel/preset-env',
{
targets: {
electron: '3.0.2',
},
modules: false,
useBuiltIns: 'entry',
},
],
],
plugins: [
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-do-expressions',
[
// used only for babel helpers
'@babel/plugin-transform-runtime',
{
// regenerator runtime should be used from global polyfill
regenerator: false,
// define babel helpers as es modules
useESModules: true,
},
],
],
},
},
},
{
test: /\.node$/,
loader: 'native-ext-loader',
},
// Common Image Formats
{
test: /\.(?:ico|gif|png|jpg|jpeg|eot|webp)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
},
},
],
},
],
},
/**
* Disables webpack processing of __dirname and __filename.
* If you run the bundle in node.js it falls back to these values of node.js.
* https://github.com/webpack/webpack/issues/2010
*/
node: {
__dirname: false,
__filename: false,
},
});