From cadc4e5220e70211ef1227413a60ef2ef9acfed6 Mon Sep 17 00:00:00 2001 From: wanglihui <1769794040@qq.com> Date: Thu, 27 Jun 2024 15:03:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=E4=BF=AE=E5=A4=8DTerserPlug?= =?UTF-8?q?in=E7=BC=96=E8=AF=91=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/config-overrides.js | 98 +++++++++++++----------------------- 1 file changed, 34 insertions(+), 64 deletions(-) diff --git a/apps/web/config-overrides.js b/apps/web/config-overrides.js index b0a616e..afa1d81 100644 --- a/apps/web/config-overrides.js +++ b/apps/web/config-overrides.js @@ -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()) } \ No newline at end of file