2018-03-18 19:59:38 +08:00
|
|
|
// This config is for building dist files
|
2023-04-05 10:05:59 +08:00
|
|
|
// const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
2023-04-23 19:18:11 +08:00
|
|
|
const { EsbuildPlugin } = require('esbuild-loader');
|
2022-03-12 09:56:32 +08:00
|
|
|
const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin');
|
2020-03-15 13:12:47 +08:00
|
|
|
const getWebpackConfig = require('./antd-tools/getWebpackConfig');
|
2018-03-18 19:59:38 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
function addLocales(webpackConfig) {
|
|
|
|
let packageName = 'antd-with-locales';
|
2018-03-18 19:59:38 +08:00
|
|
|
if (webpackConfig.entry['antd.min']) {
|
2019-01-12 11:33:27 +08:00
|
|
|
packageName += '.min';
|
2018-03-18 19:59:38 +08:00
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
webpackConfig.entry[packageName] = './index-with-locales.js';
|
|
|
|
webpackConfig.output.filename = '[name].js';
|
2018-03-18 19:59:38 +08:00
|
|
|
}
|
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
function externalDayjs(config) {
|
2023-02-23 17:20:38 +08:00
|
|
|
config.externals.dayjs = {
|
2022-08-07 15:10:53 +08:00
|
|
|
dayjs: {
|
|
|
|
root: 'dayjs',
|
|
|
|
commonjs2: 'dayjs',
|
|
|
|
commonjs: 'dayjs',
|
|
|
|
amd: 'dayjs',
|
|
|
|
},
|
2023-02-23 17:20:38 +08:00
|
|
|
};
|
2022-08-07 15:10:53 +08:00
|
|
|
config.externals.push(function ({ _context, request }, callback) {
|
|
|
|
if (/^dayjs\/plugin\//.test(request)) {
|
2023-02-17 22:01:30 +08:00
|
|
|
const name = request.replace(/\//g, '_');
|
2022-08-07 15:10:53 +08:00
|
|
|
return callback(null, {
|
|
|
|
root: name,
|
|
|
|
commonjs2: name,
|
|
|
|
commonjs: name,
|
|
|
|
amd: name,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
callback();
|
|
|
|
});
|
2018-03-18 19:59:38 +08:00
|
|
|
}
|
|
|
|
|
2023-02-23 17:20:38 +08:00
|
|
|
const webpackConfig = getWebpackConfig(false);
|
2021-01-14 17:33:17 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
if (process.env.RUN_ENV === 'PRODUCTION') {
|
|
|
|
webpackConfig.forEach(config => {
|
|
|
|
addLocales(config);
|
2023-02-23 17:20:38 +08:00
|
|
|
externalDayjs(config);
|
2021-09-25 16:51:32 +08:00
|
|
|
// Reduce non-minified dist files size
|
|
|
|
config.optimization.usedExports = true;
|
2022-03-12 09:56:32 +08:00
|
|
|
// use esbuild
|
|
|
|
if (process.env.ESBUILD || process.env.CSB_REPO) {
|
2023-04-23 19:18:11 +08:00
|
|
|
config.optimization.minimizer[0] = new EsbuildPlugin({
|
2022-03-12 09:56:32 +08:00
|
|
|
target: 'es2015',
|
|
|
|
css: true,
|
|
|
|
});
|
|
|
|
}
|
2023-04-05 10:05:59 +08:00
|
|
|
// config.plugins.push(
|
|
|
|
// new BundleAnalyzerPlugin({
|
|
|
|
// analyzerMode: 'static',
|
|
|
|
// openAnalyzer: false,
|
|
|
|
// reportFilename: '../report.html',
|
|
|
|
// }),
|
|
|
|
// );
|
2022-03-12 09:56:32 +08:00
|
|
|
|
|
|
|
if (!process.env.NO_DUP_CHECK) {
|
|
|
|
config.plugins.push(
|
|
|
|
new DuplicatePackageCheckerPlugin({
|
|
|
|
verbose: true,
|
|
|
|
emitError: true,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
2021-01-14 17:33:17 +08:00
|
|
|
});
|
2021-09-25 16:51:32 +08:00
|
|
|
}
|
2021-01-14 17:33:17 +08:00
|
|
|
|
2023-04-23 19:18:11 +08:00
|
|
|
module.exports = [...webpackConfig];
|