mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
chore: Update webpack.config.js (#51098)
This commit is contained in:
parent
e8b0fc4925
commit
34cf399e10
@ -7,86 +7,85 @@ const CircularDependencyPlugin = require('circular-dependency-plugin');
|
|||||||
const DuplicatePackageCheckerPlugin = require('@madccc/duplicate-package-checker-webpack-plugin');
|
const DuplicatePackageCheckerPlugin = require('@madccc/duplicate-package-checker-webpack-plugin');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
function addLocales(webpackConfig) {
|
function addLocales(config) {
|
||||||
|
const newConfig = { ...config }; // Avoid mutating the original config
|
||||||
let packageName = 'antd-with-locales';
|
let packageName = 'antd-with-locales';
|
||||||
if (webpackConfig.entry['antd.min']) {
|
if (newConfig.entry['antd.min']) {
|
||||||
packageName += '.min';
|
packageName += '.min';
|
||||||
}
|
}
|
||||||
webpackConfig.entry[packageName] = './index-with-locales.js';
|
newConfig.entry[packageName] = './index-with-locales.js';
|
||||||
webpackConfig.output.filename = '[name].js';
|
newConfig.output.filename = '[name].js';
|
||||||
|
return newConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
function externalDayjs(config) {
|
function externalDayjs(config) {
|
||||||
config.externals.dayjs = {
|
const newConfig = { ...config }; // Shallow copy for safety
|
||||||
|
newConfig.externals.dayjs = {
|
||||||
root: 'dayjs',
|
root: 'dayjs',
|
||||||
commonjs2: 'dayjs',
|
commonjs2: 'dayjs',
|
||||||
commonjs: 'dayjs',
|
commonjs: 'dayjs',
|
||||||
amd: 'dayjs',
|
amd: 'dayjs',
|
||||||
};
|
};
|
||||||
|
return newConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
function externalCssinjs(config) {
|
function externalCssinjs(config) {
|
||||||
config.resolve = config.resolve || {};
|
const newConfig = { ...config }; // Shallow copy for safety
|
||||||
config.resolve.alias = config.resolve.alias || {};
|
newConfig.resolve = newConfig.resolve || {};
|
||||||
|
newConfig.resolve.alias = newConfig.resolve.alias || {};
|
||||||
|
newConfig.resolve.alias['@ant-design/cssinjs'] = path.resolve(__dirname, 'alias/cssinjs');
|
||||||
|
return newConfig;
|
||||||
|
}
|
||||||
|
|
||||||
config.resolve.alias['@ant-design/cssinjs'] = path.resolve(__dirname, 'alias/cssinjs');
|
function addPluginsForProduction(config) {
|
||||||
|
const newConfig = { ...config }; // Shallow copy for safety
|
||||||
|
if (!process.env.CI || process.env.ANALYZER) {
|
||||||
|
newConfig.plugins.push(
|
||||||
|
new BundleAnalyzerPlugin({
|
||||||
|
analyzerMode: 'static',
|
||||||
|
openAnalyzer: false,
|
||||||
|
reportFilename: '../report.html',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (newConfig.mode === 'production' && !process.env.PRODUCTION_ONLY) {
|
||||||
|
newConfig.plugins.push(
|
||||||
|
new DuplicatePackageCheckerPlugin({
|
||||||
|
verbose: true,
|
||||||
|
emitError: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
newConfig.plugins.push(
|
||||||
|
codecovWebpackPlugin({
|
||||||
|
enableBundleAnalysis: process.env.CODECOV_TOKEN !== undefined,
|
||||||
|
bundleName: 'antd.min',
|
||||||
|
uploadToken: process.env.CODECOV_TOKEN,
|
||||||
|
}),
|
||||||
|
new CircularDependencyPlugin({
|
||||||
|
failOnError: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
return newConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
let webpackConfig = getWebpackConfig(false);
|
let webpackConfig = getWebpackConfig(false);
|
||||||
|
|
||||||
// Used for `size-limit` ci which only need to check min files
|
|
||||||
if (process.env.PRODUCTION_ONLY) {
|
if (process.env.PRODUCTION_ONLY) {
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('🍐 Build production only');
|
console.log('🍐 Build production only');
|
||||||
webpackConfig = webpackConfig.filter((config) => config.mode === 'production');
|
webpackConfig = webpackConfig.filter((config) => config.mode === 'production');
|
||||||
}
|
}
|
||||||
|
|
||||||
// RUN_ENV: https://github.com/ant-design/antd-tools/blob/14ee166fc1f4ab5e87da45ee3b0643a8325f1bc3/lib/gulpfile.js#L48
|
|
||||||
if (process.env.RUN_ENV === 'PRODUCTION') {
|
if (process.env.RUN_ENV === 'PRODUCTION') {
|
||||||
webpackConfig.forEach((config) => {
|
webpackConfig = webpackConfig.map((config) => {
|
||||||
addLocales(config);
|
let newConfig = addLocales(config);
|
||||||
externalDayjs(config);
|
newConfig = externalDayjs(newConfig);
|
||||||
externalCssinjs(config);
|
newConfig = externalCssinjs(newConfig);
|
||||||
// Reduce non-minified dist files size
|
newConfig.optimization.usedExports = true;
|
||||||
config.optimization.usedExports = true;
|
newConfig = addPluginsForProduction(newConfig);
|
||||||
|
return newConfig;
|
||||||
if (!process.env.CI || process.env.ANALYZER) {
|
|
||||||
config.plugins.push(
|
|
||||||
new BundleAnalyzerPlugin({
|
|
||||||
analyzerMode: 'static',
|
|
||||||
openAnalyzer: false,
|
|
||||||
reportFilename: '../report.html',
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.mode !== 'production') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!process.env.PRODUCTION_ONLY) {
|
|
||||||
config.plugins.push(
|
|
||||||
new DuplicatePackageCheckerPlugin({
|
|
||||||
verbose: true,
|
|
||||||
emitError: true,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
config.plugins.push(
|
|
||||||
codecovWebpackPlugin({
|
|
||||||
enableBundleAnalysis: process.env.CODECOV_TOKEN !== undefined,
|
|
||||||
bundleName: 'antd.min',
|
|
||||||
uploadToken: process.env.CODECOV_TOKEN,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
config.plugins.push(
|
|
||||||
new CircularDependencyPlugin({
|
|
||||||
// add errors to webpack instead of warnings
|
|
||||||
failOnError: true,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user