diff --git a/.bundle-analyzerrc b/.bundle-analyzerrc new file mode 100644 index 0000000000..4926fc335a --- /dev/null +++ b/.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" + } + ] +} diff --git a/package.json b/package.json index b1137c233f..c5ea3c7087 100644 --- a/package.json +++ b/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", diff --git a/webpack.config.js b/webpack.config.js index cd1f49c27c..36d8341e3c 100644 --- a/webpack.config.js +++ b/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);