-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig-overrides.js
76 lines (65 loc) · 2.05 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const path = require('path');
const fs = require('fs');
const {
override,
fixBabelImports,
addWebpackPlugin,
} = require('customize-cra');
const CopyPlugin = require('copy-webpack-plugin');
const paths = require('react-scripts/config/paths');
const webpack = require('webpack');
const webpackObfuscator = require('webpack-obfuscator');
const packageConfigJSON = require('./package-config.json');
const { version, buildPath, homepage} = packageConfigJSON;
const configPath = `./src/configs/config.js`
paths.appBuild = path.join(
path.dirname(paths.appBuild),
`build/${buildPath}`
);
paths.publicUrlOrPath =homepage;
const configResult = override(
fixBabelImports("import", {
libraryName: "antd",
libraryDirectory: "es",
style: true, //自动打包相关的样式 默认为 style:css
}),
addWebpackPlugin(
new CopyPlugin({
patterns: [
{
from: configPath,
to: `${version}/config.js`,
},
],
})
),
(config) => {
const isEnvDevelopment = config.mode === 'development';
const isEnvProduction = config.mode === 'production';
config.optimization.runtimeChunk = false;
config.optimization.splitChunks = {
cacheGroups: {
default: false,
},
};
config.output = {
...config.output,
filename: isEnvProduction
? version + '/js/[name].[contenthash:8].js'
: isEnvDevelopment && version + '/js/bundle.js',
chunkFilename: isEnvProduction
? version + '/js/[name].[contenthash:8].chunk.js'
: isEnvDevelopment && version + '/js/[name].chunk.js',
};
config.plugins[5].options.filename =
version + '/css/[name].[contenthash:8].css';
config.plugins[5].options.chunkFilename =
version + '/css/[name].[contenthash:8].css';
// 删除pwa serverWorker相关内容
config.plugins.splice(8, 1);
// 删除asset-manifest.json相关内容
config.plugins.splice(6, 1);
return config;
}
);
module.exports = configResult;