vite 構建移除 console

vite 3.x 已經將 esbuild 作爲默認構建選項,你可以通過如下配置在構建時移除代碼中的 console.logdebugger

// vite.config.ts
import { defineConfig } from 'vite'

export default defineConfig({
    build:{
      minify: 'terser', // 默認
    },
    esbuild: {
      drop: ['console', 'debugger'],
    },
});

如果你仍然使用 terser 作爲構建工具,可以通過如下配置實現此目的。

// vite.config.ts
import { defineConfig } from 'vite'

export default defineConfig({
  build: {
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true,
      },
    },
  },
})

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章