Browse Source

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
pull/24407/head
偏右 5 years ago
committed by GitHub
parent
commit
1e11c83e74
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      .bundle-analyzerrc
  2. 1
      package.json
  3. 33
      webpack.config.js

24
.bundle-analyzerrc

@ -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"
}
]
}

1
package.json

@ -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",

33
webpack.config.js

@ -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);

Loading…
Cancel
Save