diff --git a/alias/cssinjs.js b/alias/cssinjs.js new file mode 100644 index 0000000000..ab46a110ab --- /dev/null +++ b/alias/cssinjs.js @@ -0,0 +1,19 @@ +/* eslint-disable global-require, import/no-unresolved */ + +// This is a alias proxy, which will use global `@ant-design/cssinjs` first. +// Use local if global not found. +let cssinjs; + +if (typeof window !== 'undefined' && window.antdCssinjs) { + // Use window UMD version + cssinjs = window.antdCssinjs; +} else if (typeof global !== 'undefined' && global.antdCssinjs) { + // Use global UMD version + cssinjs = global.antdCssinjs; +} else { + // Use local version. + // Use relative path since webpack will also replace module here. + cssinjs = require('../node_modules/@ant-design/cssinjs'); +} + +module.exports = cssinjs; diff --git a/webpack.config.js b/webpack.config.js index 829a4f7251..097e1dddf9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -5,6 +5,7 @@ const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); const { EsbuildPlugin } = require('esbuild-loader'); const CircularDependencyPlugin = require('circular-dependency-plugin'); const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin'); +const path = require('path'); function addLocales(webpackConfig) { let packageName = 'antd-with-locales'; @@ -24,6 +25,13 @@ function externalDayjs(config) { }; } +function externalCssinjs(config) { + config.resolve = config.resolve || {}; + config.resolve.alias = config.resolve.alias || {}; + + config.resolve.alias['@ant-design/cssinjs'] = path.resolve(__dirname, 'alias/cssinjs'); +} + let webpackConfig = getWebpackConfig(false); // Used for `size-limit` ci which only need to check min files @@ -37,6 +45,8 @@ if (process.env.RUN_ENV === 'PRODUCTION') { webpackConfig.forEach((config) => { addLocales(config); externalDayjs(config); + externalCssinjs(config); + // Reduce non-minified dist files size config.optimization.usedExports = true; // use esbuild