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,
            },
        },
    },
});
相关推荐
小兵张健9 分钟前
开源 playwright-pool 会话池来了
前端·javascript·github
IT_陈寒3 小时前
Python开发者必知的5大性能陷阱:90%的人都踩过的坑!
前端·人工智能·后端
codingWhat4 小时前
介绍一个手势识别库——AlloyFinger
前端·javascript·vue.js
代码老中医4 小时前
2026年CSS彻底疯了:这6个新特性让我删掉了三分之一JS代码
前端
不会敲代码14 小时前
Zustand:轻量级状态管理,从入门到实践
前端·typescript
踩着两条虫4 小时前
VTJ.PRO 双向代码转换原理揭秘
前端·vue.js·人工智能
扉川川4 小时前
OpenClaw 架构解析:一个生产级 AI Agent 是如何设计的
前端·人工智能
远山枫谷4 小时前
一文理清页面/组件通信与 Store 全局状态管理
前端·微信小程序
codingWhat4 小时前
手撸一个「能打」的 React Table 组件
前端·javascript·react.js
HelloReader4 小时前
Tauri 应用安全从开发到发布的威胁防御指南
前端