Skip to content

Commit

Permalink
chore: umd version will try to reuse global @ant-design/cssinjs fir…
Browse files Browse the repository at this point in the history
…st (ant-design#46009)

* chore: alias of it

* chore: comment
  • Loading branch information
zombieJ authored Nov 22, 2023
1 parent e5a6966 commit 3233ac4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions alias/cssinjs.js
Original file line number Diff line number Diff line change
@@ -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;
10 changes: 10 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3233ac4

Please sign in to comment.