console.log导致内存泄露 打包时自动去掉console.log方法

webpack通过工具:terser

使用前需要先安装一下

vue.config.js

javascript 复制代码
const { defineConfig } = require('@vue/cli-servise');
module.exports = defineConfig({
    transpileDependencies:true,
    terser:{
        terserOptions:{
            compress:{
                drop_console:true,
                drop_debugger:true,
                },
             },
            },
           });

然后直接打包就会自动去掉console.log,不影响开发环境

如果是vue3+vite

vite.config.js

javascript 复制代码
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
    plugins:[vue()],
    build:{
        minify:'terser',
        terserOptions:{
            compress:{
                drop_console:true,
                drop_debugger:true,
            },
        },
    },
});
相关推荐
从零开始学习人工智能10 分钟前
快速搭建B/S架构HTML演示页:从工具选择到实战落地
前端·架构·html
虫虫rankourin1 小时前
在 create-react-app (CRA) 创建的应用中使用 react-router-dom v7以及懒加载的使用方法
前端·react.js
小刘鸭地下城1 小时前
Web安全必备:关键 HTTP 标头解析
前端
yddddddy1 小时前
html基本知识
前端·html
荣达2 小时前
koa洋葱模型理解
前端·后端·node.js
reembarkation2 小时前
使用pdfjs-dist 预览pdf,并添加文本层的实现
前端·javascript·pdf
KenXu2 小时前
F2C-PTD工具将需求快速转换为代码实践
前端
给月亮点灯|3 小时前
Vue3基础知识-setup()、ref()和reactive()
前端·javascript·vue.js
芜青3 小时前
【Vue2手录12】单文件组件SFC
前端·javascript·vue.js
冷冷的菜哥3 小时前
react实现无缝轮播组件
前端·react.js·typescript·前端框架·无缝轮播