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文件:
進(jìn)行如下配置,主要是build塊的配置
import { defineConfig,loadEnv } from 'vite' import vue from '@vitejs/plugin-vue' export default defineConfig({ plugins: [vue()], build:{ minify: 'terser', terserOptions: { compress: { //生產(chǎn)環(huán)境時移除console.log() drop_console: true, drop_debugger: true, }, }, }, })
console.log導(dǎo)致內(nèi)存泄露 打包時自動去掉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, }, }, }, });
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
VueJs單頁應(yīng)用實現(xiàn)微信網(wǎng)頁授權(quán)及微信分享功能示例
本篇文章主要介紹了VueJs單頁應(yīng)用實現(xiàn)微信網(wǎng)頁授權(quán)及微信分享功能示例,具有一定的參考價值,有興趣的可以了解一下2017-07-07關(guān)于Element UI table 順序拖動方式
這篇文章主要介紹了關(guān)于Element UI table 順序拖動方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08詳解Vue的computed(計算屬性)使用實例之TodoList
本篇文章主要介紹了詳解Vue的computed(計算屬性)使用實例之TodoList,具有一定的參考價值,有興趣的可以了解一下2017-08-08Vue的hover/click事件如何動態(tài)改變顏色和背景色
這篇文章主要介紹了Vue的hover/click事件如何動態(tài)改變顏色和背景色問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11vue中利用three.js實現(xiàn)全景圖的完整示例
這篇文章主要給大家介紹了關(guān)于vue中利用three.js實現(xiàn)全景圖的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12