chore: umd version will try to reuse global @ant-design/cssinjs first (#46009)

* chore: alias of it

* chore: comment
This commit is contained in:
二货爱吃白萝卜 2023-11-22 15:04:55 +08:00 committed by GitHub
parent e5a69664c3
commit 3233ac498f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

19
alias/cssinjs.js Normal file
View File

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

View File

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