test: add @bundle-analyzer/webpack-plugin (#24399)

* add @bundle-analyzer/webpack-plugin

* add .bundle-analyzerrc

* use process.env.BUNDLE_ANALYZER_TOKEN

* more dist files

* fix ci fail
This commit is contained in:
偏右 2020-05-22 18:46:03 +08:00 committed by GitHub
parent 2932b39c88
commit 1e11c83e74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 10 deletions

24
.bundle-analyzerrc Normal file
View File

@ -0,0 +1,24 @@
{
"files": [
{
"test": "./dist/antd.min.js",
"maxSize": "300 kB",
"compression": "gzip"
},
{
"test": "./dist/antd.min.css",
"maxSize": "65 kB",
"compression": "gzip"
},
{
"test": "./dist/antd.dark.min.css",
"maxSize": "65 kB",
"compression": "gzip"
},
{
"test": "./dist/antd.compact.min.css",
"maxSize": "65 kB",
"compression": "gzip"
}
]
}

View File

@ -153,6 +153,7 @@
"@ant-design/colors": "^4.0.0",
"@ant-design/hitu": "^0.0.0-alpha.13",
"@ant-design/tools": "^8.2.0",
"@bundle-analyzer/webpack-plugin": "^0.5.1",
"@qixian.cs/github-contributors-list": "^1.0.3",
"@stackblitz/sdk": "^1.3.0",
"@types/classnames": "^2.2.8",

View File

@ -3,6 +3,7 @@
const getWebpackConfig = require('@ant-design/tools/lib/getWebpackConfig');
const IgnoreEmitPlugin = require('ignore-emit-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const BundleAnalyzerPluginCom = require('@bundle-analyzer/webpack-plugin');
const EsbuildPlugin = require('esbuild-webpack-plugin').default;
const darkVars = require('./scripts/dark-vars');
const compactVars = require('./scripts/compact-vars');
@ -52,6 +53,17 @@ function injectWarningCondition(config) {
});
}
function addBundleAnalyzerPluginCom(config) {
if (!process.env.CIRCLECI || process.env.RUN_ENV !== 'PRODUCTION') {
return;
}
config.plugins.push(
new BundleAnalyzerPluginCom({
token: process.env.BUNDLE_ANALYZER_TOKEN,
}),
);
}
function processWebpackThemeConfig(themeConfig, theme, vars) {
themeConfig.forEach(config => {
ignoreMomentLocale(config);
@ -79,6 +91,8 @@ function processWebpackThemeConfig(themeConfig, theme, vars) {
const themeReg = new RegExp(`${theme}(.min)?\\.js(\\.map)?$`);
// ignore emit ${theme} entry js & js.map file
config.plugins.push(new IgnoreEmitPlugin(themeReg));
addBundleAnalyzerPluginCom(config);
});
}
@ -102,16 +116,15 @@ if (process.env.RUN_ENV === 'PRODUCTION') {
config.optimization.minimizer[0] = new EsbuildPlugin();
}
// skip codesandbox ci
if (!process.env.CSB_REPO) {
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
reportFilename: '../report.html',
}),
);
}
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
reportFilename: '../report.html',
}),
);
addBundleAnalyzerPluginCom(config);
});
processWebpackThemeConfig(webpackDarkConfig, 'dark', darkVars);