亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vite如何build時(shí)清除console.log()問題

 更新時(shí)間:2024年07月01日 15:29:01   作者:biaobiaogege  
這篇文章主要介紹了vite如何build時(shí)清除console.log()問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

vite如何build時(shí)清除console.log()

1、在vue-cli中移除console,下載babel-plugin-transform-remove-console插件,配置 babel.config.js文件

2、vite build清除console.log():vscode項(xiàng)目中,找到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)境時(shí)移除console.log()
            drop_console: true,
            drop_debugger: true,
        },
      },
    },
})

console.log導(dǎo)致內(nèi)存泄露 打包時(shí)自動(dòng)去掉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,
                },
             },
            },
           });

然后直接打包就會(huì)自動(dòng)去掉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é)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論