2018-11-28 15:00:03 +08:00
|
|
|
/* eslint no-param-reassign: 0 */
|
2016-10-15 17:04:30 +08:00
|
|
|
// This config is for building dist files
|
2019-08-01 15:28:16 +08:00
|
|
|
const getWebpackConfig = require('@ant-design/tools/lib/getWebpackConfig');
|
2020-06-08 18:01:50 +08:00
|
|
|
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
2024-08-13 13:32:17 +08:00
|
|
|
const { codecovWebpackPlugin } = require('@codecov/webpack-plugin');
|
2023-06-25 15:38:22 +08:00
|
|
|
const CircularDependencyPlugin = require('circular-dependency-plugin');
|
2023-11-23 20:15:12 +08:00
|
|
|
const DuplicatePackageCheckerPlugin = require('@madccc/duplicate-package-checker-webpack-plugin');
|
2023-11-22 15:04:55 +08:00
|
|
|
const path = require('path');
|
2021-09-01 10:56:50 +08:00
|
|
|
|
2024-10-03 10:47:40 +08:00
|
|
|
function addLocales(config) {
|
|
|
|
const newConfig = { ...config }; // Avoid mutating the original config
|
2017-02-17 09:36:42 +08:00
|
|
|
let packageName = 'antd-with-locales';
|
2024-10-03 10:47:40 +08:00
|
|
|
if (newConfig.entry['antd.min']) {
|
2017-02-17 09:36:42 +08:00
|
|
|
packageName += '.min';
|
|
|
|
}
|
2024-10-03 10:47:40 +08:00
|
|
|
newConfig.entry[packageName] = './index-with-locales.js';
|
|
|
|
newConfig.output.filename = '[name].js';
|
|
|
|
return newConfig;
|
2017-02-17 09:36:42 +08:00
|
|
|
}
|
|
|
|
|
2022-03-30 15:55:40 +08:00
|
|
|
function externalDayjs(config) {
|
2024-10-03 10:47:40 +08:00
|
|
|
const newConfig = { ...config }; // Shallow copy for safety
|
|
|
|
newConfig.externals.dayjs = {
|
2022-03-30 15:55:40 +08:00
|
|
|
root: 'dayjs',
|
|
|
|
commonjs2: 'dayjs',
|
|
|
|
commonjs: 'dayjs',
|
|
|
|
amd: 'dayjs',
|
|
|
|
};
|
2024-10-03 10:47:40 +08:00
|
|
|
return newConfig;
|
2022-03-30 15:55:40 +08:00
|
|
|
}
|
|
|
|
|
2023-11-22 15:04:55 +08:00
|
|
|
function externalCssinjs(config) {
|
2024-10-03 10:47:40 +08:00
|
|
|
const newConfig = { ...config }; // Shallow copy for safety
|
|
|
|
newConfig.resolve = newConfig.resolve || {};
|
|
|
|
newConfig.resolve.alias = newConfig.resolve.alias || {};
|
|
|
|
newConfig.resolve.alias['@ant-design/cssinjs'] = path.resolve(__dirname, 'alias/cssinjs');
|
|
|
|
return newConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
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',
|
2024-12-12 10:22:30 +08:00
|
|
|
}),
|
2024-10-03 10:47:40 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if (newConfig.mode === 'production' && !process.env.PRODUCTION_ONLY) {
|
|
|
|
newConfig.plugins.push(
|
|
|
|
new DuplicatePackageCheckerPlugin({
|
|
|
|
verbose: true,
|
|
|
|
emitError: true,
|
2024-12-12 10:22:30 +08:00
|
|
|
}),
|
2024-10-03 10:47:40 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
newConfig.plugins.push(
|
|
|
|
codecovWebpackPlugin({
|
|
|
|
enableBundleAnalysis: process.env.CODECOV_TOKEN !== undefined,
|
|
|
|
bundleName: 'antd.min',
|
|
|
|
uploadToken: process.env.CODECOV_TOKEN,
|
|
|
|
}),
|
|
|
|
new CircularDependencyPlugin({
|
|
|
|
failOnError: true,
|
2024-12-12 10:22:30 +08:00
|
|
|
}),
|
2024-10-03 10:47:40 +08:00
|
|
|
);
|
2023-11-22 15:04:55 +08:00
|
|
|
|
2024-10-03 10:47:40 +08:00
|
|
|
return newConfig;
|
2023-11-22 15:04:55 +08:00
|
|
|
}
|
|
|
|
|
2023-08-10 15:17:40 +08:00
|
|
|
let webpackConfig = getWebpackConfig(false);
|
|
|
|
|
|
|
|
if (process.env.PRODUCTION_ONLY) {
|
|
|
|
console.log('🍐 Build production only');
|
|
|
|
webpackConfig = webpackConfig.filter((config) => config.mode === 'production');
|
|
|
|
}
|
2020-05-08 15:48:21 +08:00
|
|
|
|
2020-03-29 10:39:46 +08:00
|
|
|
if (process.env.RUN_ENV === 'PRODUCTION') {
|
2024-10-03 10:47:40 +08:00
|
|
|
webpackConfig = webpackConfig.map((config) => {
|
|
|
|
let newConfig = addLocales(config);
|
|
|
|
newConfig = externalDayjs(newConfig);
|
|
|
|
newConfig = externalCssinjs(newConfig);
|
|
|
|
newConfig.optimization.usedExports = true;
|
|
|
|
newConfig = addPluginsForProduction(newConfig);
|
|
|
|
return newConfig;
|
2019-12-18 21:07:14 +08:00
|
|
|
});
|
2017-10-19 19:06:16 +08:00
|
|
|
}
|
|
|
|
|
2022-07-05 21:55:21 +08:00
|
|
|
module.exports = [...webpackConfig];
|