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
|
|
|
|
2017-02-17 09:36:42 +08:00
|
|
|
function addLocales(webpackConfig) {
|
|
|
|
let packageName = 'antd-with-locales';
|
|
|
|
if (webpackConfig.entry['antd.min']) {
|
|
|
|
packageName += '.min';
|
|
|
|
}
|
|
|
|
webpackConfig.entry[packageName] = './index-with-locales.js';
|
|
|
|
webpackConfig.output.filename = '[name].js';
|
|
|
|
}
|
|
|
|
|
2022-03-30 15:55:40 +08:00
|
|
|
function externalDayjs(config) {
|
|
|
|
config.externals.dayjs = {
|
|
|
|
root: 'dayjs',
|
|
|
|
commonjs2: 'dayjs',
|
|
|
|
commonjs: 'dayjs',
|
|
|
|
amd: 'dayjs',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-11-22 15:04:55 +08:00
|
|
|
function externalCssinjs(config) {
|
|
|
|
config.resolve = config.resolve || {};
|
|
|
|
config.resolve.alias = config.resolve.alias || {};
|
|
|
|
|
|
|
|
config.resolve.alias['@ant-design/cssinjs'] = path.resolve(__dirname, 'alias/cssinjs');
|
|
|
|
}
|
|
|
|
|
2023-08-10 15:17:40 +08:00
|
|
|
let webpackConfig = getWebpackConfig(false);
|
|
|
|
|
|
|
|
// Used for `size-limit` ci which only need to check min files
|
|
|
|
if (process.env.PRODUCTION_ONLY) {
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log('🍐 Build production only');
|
|
|
|
webpackConfig = webpackConfig.filter((config) => config.mode === 'production');
|
|
|
|
}
|
2020-05-08 15:48:21 +08:00
|
|
|
|
2024-08-27 09:55:59 +08:00
|
|
|
// RUN_ENV: https://github.com/ant-design/antd-tools/blob/14ee166fc1f4ab5e87da45ee3b0643a8325f1bc3/lib/gulpfile.js#L48
|
2020-03-29 10:39:46 +08:00
|
|
|
if (process.env.RUN_ENV === 'PRODUCTION') {
|
2022-11-19 13:47:33 +08:00
|
|
|
webpackConfig.forEach((config) => {
|
2020-03-29 10:39:46 +08:00
|
|
|
addLocales(config);
|
2022-03-30 15:55:40 +08:00
|
|
|
externalDayjs(config);
|
2023-11-22 15:04:55 +08:00
|
|
|
externalCssinjs(config);
|
2020-03-29 10:39:46 +08:00
|
|
|
// Reduce non-minified dist files size
|
|
|
|
config.optimization.usedExports = true;
|
2020-05-14 15:57:04 +08:00
|
|
|
|
2023-05-31 10:16:19 +08:00
|
|
|
if (!process.env.CI || process.env.ANALYZER) {
|
2022-05-27 21:49:16 +08:00
|
|
|
config.plugins.push(
|
|
|
|
new BundleAnalyzerPlugin({
|
|
|
|
analyzerMode: 'static',
|
|
|
|
openAnalyzer: false,
|
|
|
|
reportFilename: '../report.html',
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
2021-08-05 15:30:03 +08:00
|
|
|
|
2024-08-27 09:55:59 +08:00
|
|
|
if (config.mode !== 'production') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!process.env.PRODUCTION_ONLY) {
|
2021-09-13 15:59:57 +08:00
|
|
|
config.plugins.push(
|
|
|
|
new DuplicatePackageCheckerPlugin({
|
|
|
|
verbose: true,
|
|
|
|
emitError: true,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
2023-06-25 15:38:22 +08:00
|
|
|
|
2024-08-14 22:17:09 +08:00
|
|
|
config.plugins.push(
|
|
|
|
codecovWebpackPlugin({
|
|
|
|
enableBundleAnalysis: process.env.CODECOV_TOKEN !== undefined,
|
2024-08-27 09:55:59 +08:00
|
|
|
bundleName: 'antd.min',
|
2024-08-14 22:17:09 +08:00
|
|
|
uploadToken: process.env.CODECOV_TOKEN,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
2023-06-25 15:38:22 +08:00
|
|
|
config.plugins.push(
|
|
|
|
new CircularDependencyPlugin({
|
|
|
|
// add errors to webpack instead of warnings
|
|
|
|
failOnError: true,
|
|
|
|
}),
|
|
|
|
);
|
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];
|