ant-design/webpack.config.js

72 lines
1.9 KiB
JavaScript
Raw Normal View History

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
const getWebpackConfig = require('@ant-design/tools/lib/getWebpackConfig');
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');
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',
};
}
const webpackConfig = getWebpackConfig(false);
if (process.env.RUN_ENV === 'PRODUCTION') {
webpackConfig.forEach((config) => {
addLocales(config);
2022-03-30 15:55:40 +08:00
externalDayjs(config);
// Reduce non-minified dist files size
config.optimization.usedExports = true;
// use esbuild
if (process.env.ESBUILD || process.env.CSB_REPO) {
config.optimization.minimizer[0] = new EsbuildPlugin({
target: 'es2015',
css: true,
});
}
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',
}),
);
}
if (!process.env.NO_DUP_CHECK) {
config.plugins.push(
new DuplicatePackageCheckerPlugin({
verbose: true,
emitError: true,
}),
);
}
config.plugins.push(
new CircularDependencyPlugin({
// add errors to webpack instead of warnings
failOnError: true,
}),
);
});
2017-10-19 19:06:16 +08:00
}
module.exports = [...webpackConfig];