remove-unnecessary-console-vite
v1.0.6
Published
Remove unnecessary console.log in different environment during dev & build with Vite.js
Downloads
9
Readme
🚀 remove-unnecessary-console-vite
Vite.js插件,在生产环境或(和)开发环境,去除掉不必要的console.log()语句,并对有指定标识的语句进行保留。
Remove unnecessary console.log & reserve tagged console in different environment during dev & build with Vite.js
安装 Install
npm i remove-unnecessary-console-vite
引入 Import
// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import {RemoveUnnecessaryConsole} from 'remove-unnecessary-console'
export default defineConfig({
plugins: [
RemoveUnnecessaryConsole(),
// ... others
]
});
使用 Use RemoveUnnecessaryConsole()
RemoveUnnecessaryConsole(Num, Env)
| 属性 | 说明 | 类型 |备注| | ---- | ---- | ---- | ---- | | Num | 保留标识 | Number | console.log()中的第一个参数,当第一个参数为Num时,该日志将被保留;不填则全不保留 | Env | 保留环境 | String | "development" 或 "production"。填”development“时,开发环境下仅保留符合保留标识的日志语句,打包后的生产环境所有日志全保留;填”production“时同理相反;不填则不判断环境
示例 Examples
console.log('abc')
console.log(1, 'abc')
console.log(1, 234)
console.log(2, 'def')
console.log(1 + 2)
//①
RemoveUnnecessaryConsole(1)
//开发环境下输出 In development environment
1 'abc'
1 234
//生产环境下输出 In production environment
1 'abc'
1 234
//②
RemoveUnnecessaryConsole(2, 'production')
//开发环境下输出 In development environment
'abc'
1 'abc'
1 234
2 'def'
3
//生产环境下输出 In production environment
2 'def'
//③
RemoveUnnecessaryConsole(3, 'development')
//开发环境下输出 In development environment
//生产环境下输出 In production environment
'abc'
1 'abc'
1 234
2 'def'
3
//④
RemoveUnnecessaryConsole()
//开发环境下输出 In development environment
//生产环境下输出 In production environment