-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig-overrides.js
59 lines (52 loc) · 1.29 KB
/
config-overrides.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
const {
override,
fixBabelImports,
addLessLoader,
addWebpackAlias,
addWebpackPlugin,
// addLessLoader,
// addPostcssPlugins,
} = require("customize-cra");
const path = require("path");
const ProgressBarPlugin = require("progress-bar-webpack-plugin");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const isEnvProduction = process.env.NODE_ENV === "production";
const addCompression = () => config => {
if (isEnvProduction) {
config.plugins.push(
// gzip压缩
new CompressionWebpackPlugin({
test: /\.(css|js)$/,
// 只处理比1kb大的资源
threshold: 1024,
// 只处理压缩率低于90%的文件
minRatio: 0.9
})
);
}
return config;
};
// 查看打包后各包大小
const addAnalyzer = () => config => {
if (process.env.ANALYZER) {
config.plugins.push(new BundleAnalyzerPlugin());
}
return config;
};
module.exports = override(
fixBabelImports('import', {
libraryName: 'antd',
libraryDirectory: 'es',
style: 'css',
}),
addCompression(),
addAnalyzer(),
addWebpackPlugin(
// 终端进度条显示
new ProgressBarPlugin()
),
addWebpackAlias({
["@"]: path.resolve(__dirname, "src")
})
)