-
Notifications
You must be signed in to change notification settings - Fork 282
/
config-overrides.js
48 lines (42 loc) · 1.53 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
const JavaScriptObfuscator = require('webpack-obfuscator');
const webpack = require('webpack');
const CompressionPlugin = require('compression-webpack-plugin');
module.exports = function override(config, env) {
if (!config.plugins) {
config.plugins = [];
}
config.plugins.push(new webpack.DefinePlugin({ 'process.env.BUILD_EXPIRE': JSON.stringify(process.env.BUILD_EXPIRE) }));
const version = process.env.REACT_APP_GIT_SHA || 'snapshot';
const commonJSFilename = `commons.${version}.js`;
if (process.env.NODE_ENV === 'production') {
config.optimization = {
splitChunks: {
cacheGroups: {
commons: {
chunks: "initial",
minChunks: 1,
name: "commons",
filename: commonJSFilename,
enforce: true
}
}
}
}
if (`${process.env.BUILD_DOMAIN}` != "") {
const domains = process.env.BUILD_DOMAIN.split(',');
config.plugins.push(
new JavaScriptObfuscator({ rotateUnicodeArray: true, domainLock: domains }, [commonJSFilename])
);
}
config.plugins.push(
new CompressionPlugin({
filename: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8
})
);
}
return config;
};