-
Notifications
You must be signed in to change notification settings - Fork 2
/
craco.config.js
153 lines (151 loc) · 3.86 KB
/
craco.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const path = require('path')
const CracoLessPlugin = require('craco-less')
const apiMocker = require('mocker-api')//使用mocker-api库
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const webpack = require('webpack')
const pathResolve = pathUrl => path.join(__dirname, pathUrl)
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
const smp = new SpeedMeasurePlugin();
const WebpackBar = require('webpackbar');
module.exports = {
plugins: [
{
plugin: CracoLessPlugin,//引入less
options: {
lessLoaderOptions: {
lessOptions: {
javascriptEnabled: true //js修改主题样式
}
}
}
}
],
babel: {
plugins: [
['@babel/plugin-proposal-decorators', { legacy: true }], //装饰器
[
'import',//按需引入antd 样式
{
'libraryName': 'antd',
'libraryDirectory': 'es',
'style': true
}
]
]
},
webpack: {
// 别名
alias: {
'@': pathResolve('src')
},
optimization: {
splitChunks: {
chunks: 'async',
minSize: 40000,
maxSize: 1000000,
name: true,
maxAsyncRequests: 5, // 最大异步请求数
maxInitialRequests: 4, // 页面初始化最大异步请求数
automaticNameDelimiter: '~', // 解决命名冲突
cacheGroups: {
vender: {
name: 'vendor',
test: /[\\/]node_modules[\\/]/,
chunks: 'async',
priority: 10,
enforce: true
},
react: {
name: 'react',
test: (module) => /react|redux/.test(module.context),
chunks: 'initial',
priority: 11,
enforce: true
},
antd: {
name: 'antd',
test: (module) => {
return /ant/.test(module.context)
},
chunks: 'async',
priority: 11,
enforce: true
}
}
}
},
configureWebpack: smp.wrap({
plugins: [
// new BundleAnalyzerPlugin(),
new WebpackBar(),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new CompressionWebpackPlugin({
algorithm: 'gzip',
test: new RegExp(
'\\.(' +
['js', 'css'].join('|') +
')$'
),
threshold: 1024,
minRatio: 0.8
}),
new UglifyJsPlugin({
uglifyOptions: {
warnings: false,
compress: {
drop_debugger: true,
drop_console: true,
},
},
sourceMap: false,
parallel: true,
})
]
}),
// plugins: [
// // new BundleAnalyzerPlugin(),
// new WebpackBar(),
// new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// new CompressionWebpackPlugin({
// algorithm: 'gzip',
// test: new RegExp(
// '\\.(' +
// ['js', 'css'].join('|') +
// ')$'
// ),
// threshold: 1024,
// minRatio: 0.8
// }),
// new UglifyJsPlugin({
// uglifyOptions: {
// warnings: false,
// compress: {
// drop_debugger: true,
// drop_console: true,
// },
// },
// sourceMap: false,
// parallel: true,
// })
// ]
},
devServer: {
proxy: {
'/cmsapi': {
target: '',
changeOrigin: true,
pathRewrite: {
'^/cmsapi': ''
}
}
},
before (app) {
//如果使用mocker-api库
if (process.env.MOCKER_ENV) {
apiMocker(app, path.resolve('./mocker/index.js'), {})
}
}
}
}