ant-design/webpack.config.js
dependabot[bot] 3669d8e226
chore(deps-dev): bump esbuild-loader from 2.21.0 to 3.0.0 (#40663)
* chore(deps-dev): bump esbuild-loader from 2.21.0 to 3.0.0

Bumps [esbuild-loader](https://github.com/esbuild-kit/esbuild-loader) from 2.21.0 to 3.0.0.
- [Release notes](https://github.com/esbuild-kit/esbuild-loader/releases)
- [Commits](https://github.com/esbuild-kit/esbuild-loader/compare/v2.21.0...v3.0.0)

---
updated-dependencies:
- dependency-name: esbuild-loader
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore: rename to EsbuildPlugin

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: afc163 <afc163@gmail.com>
2023-02-09 22:10:22 +08:00

64 lines
1.7 KiB
JavaScript

/* eslint no-param-reassign: 0 */
// 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 DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin');
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';
}
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);
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,
});
}
if (!process.env.CI) {
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,
}),
);
}
});
}
module.exports = [...webpackConfig];