|
|
1 anno fa | |
|---|---|---|
| .. | ||
| dist | 1 anno fa | |
| LICENSE | 1 anno fa | |
| README.md | 1 anno fa | |
| package.json | 1 anno fa | |
生产环境下移除 console 的 vite 插件
不希望开发时的日志在生产环境下被人看到
.js,.ts,.jsx,.tsx,.vue
npm i vite-plugin-removelog -D
// vite.config.js
import Removelog from 'vite-plugin-removelog'
export default defineConfig({
plugins: [Removelog()]
})
// vite.config.js
import Removelog from 'vite-plugin-removelog'
export default defineConfig({
plugins: [
Removelog({
// 默认包含 log,warn,error
include: ['log', 'warn']
})
]
})
可以通过 normalize 来自定义哪些模块需要被作用
// vite.config.js
import Removelog from 'vite-plugin-removelog'
export default defineConfig({
plugins: [
Removelog({
// 返回 Truthy 时,模块被将作用
normalize(id) {
return /(\.vue|\.[jt]sx?)$/.test(id)
}
})
]
})
node_modules可以通过 ignoreNodeModules 忽略 node_modules 包的处理
// vite.config.js
import Removelog from 'vite-plugin-removelog'
export default defineConfig({
plugins: [
Removelog({
// 默认为 true
ignoreNodeModules: true
})
]
})
该插件不传入 normalize 时由 vite 内置的 esbuild 进行转换,当传入 normalize 时,则为 gogocode 进行转换。
gogocode 实现的转换也是导出的 👇
import { gogocodeRemovelog } from 'vite-plugin-removelog'
const code = `
const foo = 1
console.log("foo")
`
const dest = gogocodeRemovelog(code)
console.log(dest) // const foo = 1
欢迎关注 帝莎编程
Made with markthree
Published under MIT License.