-
Notifications
You must be signed in to change notification settings - Fork 677
Expand file tree
/
Copy pathwebpack.config.js
More file actions
77 lines (72 loc) · 2.14 KB
/
webpack.config.js
File metadata and controls
77 lines (72 loc) · 2.14 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
'use strict';
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { ModuleMinifierPlugin } = require('@rushstack/webpack5-module-minifier-plugin');
const { WorkerPoolMinifier } = require('@rushstack/module-minifier');
/**
* If the "--production" command-line parameter is specified when invoking Heft, then the
* "production" function parameter will be true. You can use this to enable bundling optimizations.
*/
function createWebpackConfig({ production }) {
const webpackConfig = {
// Documentation: https://webpack.js.org/configuration/mode/
mode: production ? 'production' : 'development',
resolve: {
extensions: ['.js', '.json']
},
module: {
rules: [
{
test: /\.css$/,
use: [require.resolve('style-loader'), require.resolve('css-loader')]
},
{
test: /\.js$/,
enforce: 'pre',
use: ['source-map-loader']
}
]
},
entry: {
app: path.join(__dirname, 'lib-commonjs', 'index.js'),
// Put these libraries in a separate vendor bundle
vendor: ['react', 'react-dom']
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name]_[contenthash].js'
},
performance: {
// This specifies the bundle size limit that will trigger Webpack's warning saying:
// "The following entrypoint(s) combined asset size exceeds the recommended limit."
maxEntrypointSize: 250000,
maxAssetSize: 250000
},
devServer: {
port: 9000
},
devtool: production ? undefined : 'source-map',
plugins: [
// See here for documentation: https://github.com/jantimon/html-webpack-plugin
new HtmlWebpackPlugin({
template: 'assets/index.html'
})
],
optimization: {
minimizer: [
new ModuleMinifierPlugin({
minifier: new WorkerPoolMinifier({
terserOptions: {
ecma: 2020,
mangle: true
},
verbose: true
}),
useSourceMap: true
})
]
}
};
return webpackConfig;
}
module.exports = createWebpackConfig;