vite如何build時清除console.log()問題
更新時間:2024年07月01日 15:29:01 作者:biaobiaogege
這篇文章主要介紹了vite如何build時清除console.log()問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
vite如何build時清除console.log()
1、在vue-cli中移除console,下載babel-plugin-transform-remove-console
插件,配置 babel.config.js文件
2、vite build清除console.log():vscode項目中,找到vite.config.ts文件:
進行如下配置,主要是build塊的配置
import { defineConfig,loadEnv } from 'vite' import vue from '@vitejs/plugin-vue' export default defineConfig({ plugins: [vue()], build:{ minify: 'terser', terserOptions: { compress: { //生產環(huán)境時移除console.log() drop_console: true, drop_debugger: true, }, }, }, })
console.log導致內存泄露 打包時自動去掉console.log方法
webpack通過工具:terser
使用前需要先安裝一下
- vue.config.js
const { defineConfig } = require('@vue/cli-servise'); module.exports = defineConfig({ transpileDependencies:true, terser:{ terserOptions:{ compress:{ drop_console:true, drop_debugger:true, }, }, }, });
然后直接打包就會自動去掉console.log,不影響開發(fā)環(huán)境
如果是vue3+vite
- vite.config.js
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, }, }, }, });
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
詳解Vue的computed(計算屬性)使用實例之TodoList
本篇文章主要介紹了詳解Vue的computed(計算屬性)使用實例之TodoList,具有一定的參考價值,有興趣的可以了解一下2017-08-08Vue的hover/click事件如何動態(tài)改變顏色和背景色
這篇文章主要介紹了Vue的hover/click事件如何動態(tài)改變顏色和背景色問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11