Initial commit
This commit is contained in:
55
config-overrides.js
Normal file
55
config-overrides.js
Normal file
@@ -0,0 +1,55 @@
|
||||
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 = [];
|
||||
}
|
||||
|
||||
// CRA 3 babel/TS 3.8 cannot type-check axios 0.32 bundled .d.ts (needs TS 4.1+).
|
||||
// Runtime bundle is fine; skip fork-ts-checker during production build.
|
||||
config.plugins = config.plugins.filter(
|
||||
plugin => !(plugin && plugin.constructor && plugin.constructor.name === 'ForkTsCheckerWebpackPlugin'),
|
||||
);
|
||||
|
||||
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;
|
||||
};
|
||||
Reference in New Issue
Block a user