项目上线存在的缓存问题以及存在的debugger和console.log等问题

  1. 下载uglifyjs-webpack-plugin插件
  1. 在vue.config文件中进行配置
javascript 复制代码
publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
	outputDir: 'n-sim-ipc-manage-build',
	productionSourceMap: false,
	configureWebpack: config => {
		//打包文件增加hash
		config.output.filename = `js/[name].[hash].${timeStamp}.js`
		config.output.chunkFilename = `js/[name].[hash].${timeStamp}.js`
		if (process.env.NODE_ENV === 'production') {
			config.plugins.push(
				//开启gzip压缩
				new CompressionWebpackPlugin({
					filename: '[path].gz[query]',
					algorithm: 'gzip',
					test: productionGzipExtensions,
					threshold: 1024,
					minRatio: 0.8,
				}),
				//build之后生成压缩包
				new FileManagerPlugin({
					events: {
						onEnd: {
							delete: [
								'./*.zip', // 删除之前已经存在的压缩包
							],
							archive: [
								{
									source: './n-sim-ipc-manage-build',
									destination: `./n-sim-ipc-manage-build-${dayjs().format(
										'YYYYMMDDHHmmss'
									)}.zip`,
								},
							],
						},
					},
				})
			)
			//配置打包去除console等
			config.optimization.minimizer.push(
				new UglifyJsPlugin({
					uglifyOptions: {
						output: {
							// 删除注释
							comments: false,
						},
						//生产环境自动删除console
						compress: {
							// warnings: false, // 若打包错误,则注释这行
							drop_debugger: true, //清除 debugger 语句
							drop_console: true, //清除console语句
							pure_funcs: ['console.log'],
						},
					},
					sourceMap: false,
					parallel: true,
				})
			)
		}
	},
相关推荐
半个落月17 分钟前
从零梳理 React Router:路由、懒加载、嵌套页面与登录鉴权
前端·react.js
tedcloud12344 分钟前
Impeccable 部署指南:开源前端设计工具 Linux 环境搭建实践
linux·运维·服务器·前端·人工智能·开源
默_笙1 小时前
🚩 React + TypeScript 的 Props 通信,我从"把事件对象传给父组件"进化到了"只传值"
前端·javascript
渣波1 小时前
赋予 React “多线程”:Hooks + Web Worker 并发计算架构深度解析
前端·javascript
光影少年1 小时前
Codex 斜杠指令体系与业务场景调度实战
前端·react.js·reactivex
90后的晨仔1 小时前
uni-app中如何跳转?
前端
Y3815326622 小时前
SERP API 请求体 Gzip 压缩优化实战:大数据量降带宽 80%
开发语言·前端·php
踩着两条虫3 小时前
VTJ.PRO AI Agent 技术白皮书
前端·vue.js·低代码
子兮曰3 小时前
解剖 Claude Code:从入口架构逆向工程看 AI 编程工具的信任边界设计
前端·后端·claude
先吃饱再说3 小时前
层层传递太“痛”了:useContext 给 React 组件装了个“无线遥控器”
前端·react.js·前端框架