fix: 🐛修复TerserPlugin编译报错

This commit is contained in:
wanglihui 2024-06-27 15:03:02 +08:00
parent 13fed127d7
commit cadc4e5220

View File

@ -1,70 +1,40 @@
var path = require('path') var path = require('path')
const { override, babelInclude, addWebpackPlugin, overrideDevServer } = require('customize-cra')
const { override, babelInclude, addWebpackPlugin } = require('customize-cra')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const TerserPlugin = require("terser-webpack-plugin"); const TerserPlugin = require("terser-webpack-plugin");
// module.exports = override( const addDevServerConfig = () => config => {
// // 注意是production环境启动该plugin return {
// process.env.NODE_ENV === 'production' && addWebpackPlugin( ...config,
// new UglifyJsPlugin({ client: {
// // 开启打包缓存 overlay: false
// cache: true, }
// // 开启多线程打包 };
// parallel: true, }
// uglifyOptions: {
// // 删除警告 module.exports = {
// warnings: false, webpack: function (config, env) {
// // 压缩 if (process.env.NODE_ENV === 'production') {
// compress: { config.devtool = false;
// // 移除console }
// drop_console: true, if (env === 'production') {
// // 移除debugger config.optimization = {
// drop_debugger: true minimize: true,
// } minimizer: [new TerserPlugin()],
// } };
// }) }
// ) return Object.assign(
// ) config,
override(
module.exports = function (config, env) { // 判断环境变量ANALYZER参数的值
if (process.env.NODE_ENV === 'production') { process.env.ANALYZER && addWebpackPlugin(new BundleAnalyzerPlugin()),
config.devtool = false; babelInclude([
} /* transpile (converting to es5) code in src/ and shared component library */
if (env === 'production') { path.resolve('src'),
config.optimization = { path.resolve('../../packages'),
minimize: true, ])
minimizer: [new TerserPlugin()], )(config, env)
}; )
} },
return Object.assign( devServer: overrideDevServer(addDevServerConfig())
config,
override(
// 判断环境变量ANALYZER参数的值
process.env.ANALYZER && addWebpackPlugin(new BundleAnalyzerPlugin()),
// process.env.NODE_ENV === 'production' && addWebpackPlugin(
// new UglifyJsPlugin({
// cache: true,
// // 开启多线程打包
// parallel: true,
// uglifyOptions: {
// // 删除警告
// warnings: false,
// // 压缩
// compress: {
// // 移除console
// drop_console: true,
// // 移除debugger
// drop_debugger: true
// }
// },
// })
// ),
babelInclude([
/* transpile (converting to es5) code in src/ and shared component library */
path.resolve('src'),
path.resolve('../../packages'),
])
)(config, env)
)
} }