forked from dianluyuanli-wp/jsDiffWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
92 lines (91 loc) · 3.21 KB
/
webpack.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
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
const path = require('path');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
context: path.resolve(__dirname),
entry: {
app: ['./entry/index.js']
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: path.resolve(__dirname, 'dist')
},
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
name: "common",
test: /[\\/]node_modules[\\/]/,
chunks: "initial",
minSize: 30000, // 注释掉的话也不会打出来
minChunks: 1, // 如果是2的话一个也抽不出来,因为好多只用了一次
priority: 8 // 优先级
}
},
},
},
plugins: [
new MiniCssExtractPlugin({ //对css进行打包,webpack4推荐语法
filename: "[name].css",
chunkFilename: "[name].css"
})
],
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
query: {
presets: [
'@babel/react',
'@babel/preset-env'
],
plugins: [
// 给antd做按需加载
["import", {
"libraryName": "antd",
//"libraryDirectory": "es",
"style": 'css' // `style: true` 会加载 less 文件
}],
// 这个拿来做注入代码优化的
['@babel/plugin-transform-runtime',
{
"corejs": false,
"helpers": true,
"regenerator": true,
"useESModules": false
}],
// 支持类写法
"@babel/plugin-proposal-class-properties",
'@babel/plugin-proposal-optional-chaining'
]
}
}
]
},
{
// 专门处理antd的css样式
test: /\.css$/,
include: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
'css-loader'
],
},
{
// 正常的css使用css module
test: /\.css$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
'css-loader?modules&localIdentName=[name]__[local]--[hash:base64:5]'
]
}
]
},
// mode:"development",
mode:"production",
}