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