fix: 🐛修复TerserPlugin编译报错

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

View File

@ -1,33 +1,19 @@
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: {
// // 删除警告
// warnings: false,
// // 压缩
// compress: {
// // 移除console
// drop_console: true,
// // 移除debugger
// drop_debugger: true
// }
// }
// })
// )
// )
module.exports = function (config, env) { module.exports = {
webpack: function (config, env) {
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
config.devtool = false; config.devtool = false;
} }
@ -42,24 +28,6 @@ module.exports = function (config, env) {
override( override(
// 判断环境变量ANALYZER参数的值 // 判断环境变量ANALYZER参数的值
process.env.ANALYZER && addWebpackPlugin(new BundleAnalyzerPlugin()), 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([ babelInclude([
/* transpile (converting to es5) code in src/ and shared component library */ /* transpile (converting to es5) code in src/ and shared component library */
path.resolve('src'), path.resolve('src'),
@ -67,4 +35,6 @@ module.exports = function (config, env) {
]) ])
)(config, env) )(config, env)
) )
},
devServer: overrideDevServer(addDevServerConfig())
} }