欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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項(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)境時移除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)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論