-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathconfig-overrides.js
More file actions
91 lines (86 loc) · 2.31 KB
/
config-overrides.js
File metadata and controls
91 lines (86 loc) · 2.31 KB
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
/* 脚手架基础配置项 */
const path = require("path");
const paths = require("react-scripts/config/paths");
const {
override,
disableEsLint,
adjustWorkbox,
addLessLoader,
fixBabelImports,
addWebpackAlias,
overrideDevServer
} = require("customize-cra");
const { getThemeVariables } = require("antd/dist/theme");
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const resolve = (dir) => path.join(__dirname, dir);
// 打包自定义配置
const buildCustomize = () => (config) => {
if (config.mode === "development") {
console.log("evn is development, skip build path change...");
} else if (config.mode === "production") {
console.log("evn is production, change build path...");
// 关闭sourceMap
config.devtool = false;
// 配置打包后的文件位置修改path目录
paths.appBuild = path.join(path.dirname(paths.appBuild), "dist");
config.output.path = path.join(path.dirname(config.output.path), "./dist");
// 添加js打包gzip配置
config.plugins.push(
new CompressionWebpackPlugin({
test: /\.js$|\.css$/,
threshold: 1024
})
);
}
return config;
};
// 跨域配置
const devServerConfig = () => (config) => {
return {
...config,
proxy: {
"/api": {
target: process.env.REACT_APP_API,
changeOrigin: true,
pathRewrite: {
"^/api": "/"
}
}
}
};
};
module.exports = {
webpack: override(
// do stuff with the webpack config...
disableEsLint(),
// 按需加载
fixBabelImports("import", {
libraryName: "antd",
libraryDirectory: "es",
style: true
}),
// 配置别名
addWebpackAlias({
"@": resolve("src"),
"~components": resolve("src/components"),
"~packages": resolve("src/packages"),
"~renderer": resolve("src/renderer")
}),
adjustWorkbox((wb) =>
Object.assign(wb, {
skipWaiting: true,
exclude: (wb.exclude || []).concat("index.html")
})
),
addLessLoader({
localIdentName: "[local]--[hash:base64:5]",
modifyVars: getThemeVariables({
dark: true, // 开启暗黑模式
compact: true // 开启紧凑模式
}),
javascriptEnabled: true
}),
buildCustomize()
),
devServer: overrideDevServer(devServerConfig())
};