From 678ec079bc33290ef520bec4c4777a5484ae4578 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sun, 23 Apr 2023 19:18:11 +0800 Subject: [PATCH] fix: antd.min error --- antd-tools/getWebpackConfig.js | 30 +++++++----------------------- package.json | 2 +- test.html | 23 +++++++++++++++++++++++ webpack.build.conf.js | 29 +++-------------------------- 4 files changed, 34 insertions(+), 50 deletions(-) create mode 100644 test.html diff --git a/antd-tools/getWebpackConfig.js b/antd-tools/getWebpackConfig.js index 6342b72a2..59d7bdba0 100644 --- a/antd-tools/getWebpackConfig.js +++ b/antd-tools/getWebpackConfig.js @@ -22,7 +22,7 @@ const imageOptions = { limit: 10000, }; -function getWebpackConfig(modules, esm = false) { +function getWebpackConfig(modules) { const pkg = require(getProjectPath('package.json')); const babelConfig = require('./getBabelCommonConfig')(modules || false); @@ -170,7 +170,7 @@ function getWebpackConfig(modules, esm = false) { new webpack.BannerPlugin(` ${pkg.name} v${pkg.version} -Copyright 2017-present, ant-design-vue. +Copyright 2017-present, Ant Design Vue. All rights reserved. `), new WebpackBar({ @@ -197,6 +197,9 @@ All rights reserved. }, }, ]; + config.output.library = distFileBaseName; + config.output.libraryTarget = 'umd'; + config.output.globalObject = 'this'; config.optimization = { minimizer: [ new TerserPlugin({ @@ -207,28 +210,10 @@ All rights reserved. }), ], }; - if (esm) { - entry = ['./index.esm']; - config.experiments = { - ...config.experiments, - outputModule: true, - }; - config.output.chunkFormat = 'module'; - config.output.library = { - type: 'module', - }; - config.target = 'es2019'; - } else { - config.output.libraryTarget = 'umd'; - config.output.library = distFileBaseName; - } - - const entryName = esm ? `${distFileBaseName}.esm` : distFileBaseName; - // Development const uncompressedConfig = merge({}, config, { entry: { - [entryName]: entry, + [distFileBaseName]: entry, }, mode: 'development', plugins: [ @@ -241,11 +226,10 @@ All rights reserved. // Production const prodConfig = merge({}, config, { entry: { - [`${entryName}.min`]: entry, + [`${distFileBaseName}.min`]: entry, }, mode: 'production', plugins: [ - new webpack.optimize.ModuleConcatenationPlugin(), new webpack.LoaderOptionsPlugin({ minimize: true, }), diff --git a/package.json b/package.json index 47a53ac4d..4a1bdca33 100644 --- a/package.json +++ b/package.json @@ -165,7 +165,7 @@ "duplicate-package-checker-webpack-plugin": "^3.0.0", "enquire-js": "^0.2.1", "esbuild": "~0.12.29", - "esbuild-loader": "^2.18.0", + "esbuild-loader": "^3.0.0", "escape-html": "^1.0.3", "eslint": "^8.3.0", "eslint-config-prettier": "^8.0.0", diff --git a/test.html b/test.html new file mode 100644 index 000000000..54703fa00 --- /dev/null +++ b/test.html @@ -0,0 +1,23 @@ + + +
+ + + + + + + + + + + + + + + + + + + + diff --git a/webpack.build.conf.js b/webpack.build.conf.js index 76e38eec6..84f8ddc81 100644 --- a/webpack.build.conf.js +++ b/webpack.build.conf.js @@ -1,6 +1,6 @@ // This config is for building dist files // const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); -const { ESBuildMinifyPlugin } = require('esbuild-loader'); +const { EsbuildPlugin } = require('esbuild-loader'); const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin'); const getWebpackConfig = require('./antd-tools/getWebpackConfig'); @@ -36,30 +36,7 @@ function externalDayjs(config) { }); } -function injectWarningCondition(config) { - config.module.rules.forEach(rule => { - // Remove devWarning if needed - if (rule.test.test('test.tsx')) { - rule.use = [ - ...rule.use, - { - loader: 'string-replace-loader', - options: { - search: 'devWarning(', - replace: "if (process.env.NODE_ENV !== 'production') devWarning(", - }, - }, - ]; - } - }); -} - const webpackConfig = getWebpackConfig(false); -const webpackESMConfig = getWebpackConfig(false, true); - -webpackConfig.forEach(config => { - injectWarningCondition(config); -}); if (process.env.RUN_ENV === 'PRODUCTION') { webpackConfig.forEach(config => { @@ -69,7 +46,7 @@ if (process.env.RUN_ENV === 'PRODUCTION') { config.optimization.usedExports = true; // use esbuild if (process.env.ESBUILD || process.env.CSB_REPO) { - config.optimization.minimizer[0] = new ESBuildMinifyPlugin({ + config.optimization.minimizer[0] = new EsbuildPlugin({ target: 'es2015', css: true, }); @@ -93,4 +70,4 @@ if (process.env.RUN_ENV === 'PRODUCTION') { }); } -module.exports = [...webpackConfig, ...webpackESMConfig]; +module.exports = [...webpackConfig];