-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.js
110 lines (107 loc) · 2.67 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
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
const CopyPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const { merge } = require('webpack-merge');
const commonConfig = require('./webpack.common');
const path = require('path');
module.exports = merge(commonConfig, {
mode: 'production',
output: {
filename: ({ chunk: { name } }) => {
return name.match(/webWorker$/i)
? '[name].js'
: '[name].[contenthash:8].js';
},
// publicPath: 'https://cdn.abc.com'
},
module: {
rules: [
{
test: /\.s?css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
auto: (resourcePath) => !resourcePath.includes('node_modules'),
localIdentName: '[name]__[local]__[hash:base64:5]',
},
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
[
'postcss-preset-env',
{
// Options
},
],
],
},
},
},
{
loader: 'sass-loader',
},
],
},
],
},
plugins: [
new CopyPlugin({
patterns: [
{
from: '**',
context: 'public',
globOptions: {
dot: true,
ignore: [path.resolve(process.cwd(), 'public/*.html')],
},
},
],
}),
new MiniCssExtractPlugin({
filename: 'css/main.[contenthash:8].css',
}),
],
optimization: {
minimizer: [new TerserJSPlugin({}), new CssMinimizerPlugin({})],
// 分割代码块
splitChunks: {
/**
* initial 入口 chunk,对于异步导入的文件不处理
async 异步 chunk,只对异步导入的文件处理
all 全部 chunk
*/
chunks: 'all',
name: 'common',
// minSize: 30 * 1024, // unit: byte, default around 20k
// 缓存分组
cacheGroups: {
'lodash-es': {
name: 'lodash-es',
chunks: 'all',
test: /lodash-es/,
// priority: 10,
},
react: {
name: 'react',
chunks: 'all',
test: /react/,
// priority: 10,
},
jquery: {
name: 'jquery',
chunks: 'all',
test: /jquery/,
// priority: 10,
},
},
},
},
});