-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.config.js
More file actions
109 lines (100 loc) · 2.47 KB
/
webpack.config.js
File metadata and controls
109 lines (100 loc) · 2.47 KB
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
import '@babel/polyfill';
import TerserPlugin from 'terser-webpack-plugin';
import { paths } from './src/config/paths';
const configureBabelLoader = browserlist => {
return {
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
babelrc: false,
presets: [
[
'@babel/preset-env',
{
debug: false,
modules: false,
useBuiltIns: 'usage',
targets: {
browsers: browserlist
}
}
]
],
plugins: ['@babel/plugin-syntax-dynamic-import']
}
}
};
};
const baseConfig = {
mode: 'development',
output: {
filename: '[name].js',
publicPath: '/static/scripts/'
},
devtool: 'cheap-module-source-map',
resolve: {
extensions: ['.js'],
modules: ['src/static/scripts', 'node_modules']
},
optimization: {
namedModules: true, // NamedModulesPlugin()
splitChunks: {
// CommonsChunkPlugin()
name: 'vendor',
chunks: 'all'
// minChunks: 2
},
noEmitOnErrors: true, // NoEmitOnErrorsPlugin
concatenateModules: true // ModuleConcatenationPlugin
}
};
if (process.env.NODE_ENV === 'production') {
baseConfig.mode = 'production';
baseConfig.optimization.minimizer = [
new TerserPlugin({
terserOptions: {
mangle: true,
ie8: false
}
})
];
}
const modernConfig = Object.assign({}, baseConfig, {
entry: {
bundle: paths.webpack.entry.bundle
},
module: {
rules: [
configureBabelLoader([
// The last two versions of each browser, excluding versions
// that don't support <script type="module">
'last 2 Chrome versions',
'not Chrome < 60',
'last 2 Safari versions',
'not Safari < 10.1',
'last 2 iOS versions',
'not iOS < 10.3',
'last 2 Firefox versions',
'not Firefox < 54',
'last 2 Edge versions',
'not Edge < 15'
])
]
}
// plugins: configurePlugins({ runtimeName: 'runtime' })
});
const legacyConfig = Object.assign({}, baseConfig, {
entry: {
bundle: paths.webpack.entry.bundle
},
module: {
rules: [configureBabelLoader(['> 1%', 'last 2 versions'])]
}
// plugins: configurePlugins({ runtimeName: 'runtime-legacy' })
});
// Output based on NODE_ENV
const config =
process.env.NODE_ENV === 'production' ? legacyConfig : modernConfig;
module.exports = config;