-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.development.config.js
63 lines (62 loc) · 1.79 KB
/
webpack.development.config.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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const Visualizer = require('webpack-visualizer-plugin');
const BaseConfig = require('./webpack.base.config');
const { resolvePath, SRC_DIR, DIST_DIR } = require('./tools/getPath');
module.exports = argv => {
const { plugins, ...rest } = BaseConfig(argv);
plugins.push(
new HtmlWebpackPlugin({
title: 'react-x-swiper',
filename: 'index.html',
chunks: ['index', 'vendor', 'commons', 'runtime'],
template: resolvePath(SRC_DIR, 'templates/index.html'),
meta: {
viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no',
},
minify: {
removeComments: true,
collapseWhitespace: false,
},
}),
new BundleAnalyzerPlugin(),
new Visualizer(),
);
return {
mode: 'development',
entry: {
index: resolvePath(SRC_DIR, 'entry/index.jsx'),
},
output: {
filename: '[name].js',
chunkFilename: '[name].chunk.js',
path: DIST_DIR,
},
plugins,
optimization: {
splitChunks: {
cacheGroups: {
// Split vendor code to its own chunk(s)
vendor: {
test: /node_modules/,
chunks: 'initial',
name: 'vendor',
priority: 10,
enforce: true,
},
// Split code common to all chunks to its own chunk
commons: {
name: 'commons', // The name of the chunk containing all common code
chunks: 'initial', // TODO: Document
minChunks: 2, // This is the number of modules
},
},
},
// The runtime should be in its own chunk
runtimeChunk: {
name: 'runtime',
},
},
...rest,
};
};