-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.prod.js
72 lines (71 loc) · 2.08 KB
/
webpack.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
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');
module.exports = merge(common, {
mode: 'production',
entry: {
vendor: [
'react',
'react-dom',
'redux',
'react-router-dom',
'react-redux',
'redux-actions',
'axios'
],
},
plugins: [
// new webpack.optimize.CommonsChunkPlugin({
// names: ['vendor'],
// minChunks: Infinity,
// filename: 'common.bundle.[chunkhash].js',
// }),
// new webpack.optimize.CommonsChunkPlugin({
// names: ['manifest'],
// filename: 'manifest.bundle.[chunkhash].js',
// }),
new webpack.optimize.RuntimeChunkPlugin({
name: 'manifest'
}),
new MiniCssExtractPlugin({ filename: '[name].[contenthash].css', allChunks: false }),
],
optimization: {
splitChunks: {
chunks: 'initial',
cacheGroups: { // 这里开始设置缓存的 chunks
default: {
chunks: 'initial', // 必须三选一: "initial" | "all" | "async"(默认就是异步)
minSize: 0, // 最小尺寸,默认0,
minChunks: 2, // 最小 chunk ,默认1
maxInitialRequests: 5, // 最大初始化请求书,默认1
},
vendor: {
chunks: 'initial', // 必须三选一: "initial" | "all" | "async"(默认就是异步)
names: ['vendor'], // 要缓存的 分隔出来的 chunk 名称
priority: 10, // 缓存组优先级
enforce: true,
filename: 'common.bundle.[chunkhash].js',
}
}
},
runtimeChunk: true
},
module: {
rules: [
{
test: /\.css$/,
exclude: /node_modules/,
use: [MiniCssExtractPlugin.loader, 'css-loader?modules'],
}, {
test: /\.css$/,
include: /node_modules/,
use: [MiniCssExtractPlugin.loader, 'css-loader']
},
{
test: /\.less$/,
use: [MiniCssExtractPlugin.loader, 'css-loader?modules', 'less-loader']
},
],
}
});