vite 构建移除 console
vite 3.x 已经将 esbuild 作为默认构建选项,你可以通过如下配置在构建时移除代码中的 console.log
、debugger
。
// vite.config.ts
import { defineConfig } from 'vite'
export default defineConfig({
build:{
minify: 'esbuild', // 默认
},
esbuild: {
drop: ['console', 'debugger'],
},
});
由于 vite 在开发环境使用 esbuild,你可以配置仅在生产环境启用 drop。
export default defineConfig(({ command, mode }) => ({
build:{
minify: 'esbuild', // 默认
},
esbuild: {
drop: mode === 'production' ? ['console', 'debugger'] : [],
},
})
如果你仍然使用 terser 作为构建工具,可以通过如下配置实现此目的。
// vite.config.ts
import { defineConfig } from 'vite'
export default defineConfig({
build: {
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
},
})
本文作者:guangzan
本文链接:https://www.cnblogs.com/guangzan/p/16633753.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
分类:
标签:
,
,
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步