# remove-unnecessary-console-vite

> Remove unnecessary console.log in different environment during dev & build with Vite.js

Latest version **1.0.6** (published 2023-08-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install remove-unnecessary-console-vite
pnpm add remove-unnecessary-console-vite
yarn add remove-unnecessary-console-vite
bun add remove-unnecessary-console-vite
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2023-08-09 |
| First published | 2023-08-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Adam PAN |
| Maintainers | adamaliba |
| Keywords | vite, console |

## Links

- npm: https://www.npmjs.com/package/remove-unnecessary-console-vite
- npm.io page: https://npm.io/package/remove-unnecessary-console-vite

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2023-08-09
- 1.0.5 — 2023-08-08
- 1.0.4 — 2023-08-08
- 1.0.3 — 2023-08-08
- 1.0.2 — 2023-08-08
- 1.0.1 — 2023-08-08

## 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

```js
// 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()

```js
RemoveUnnecessaryConsole(Num, Env)
```

|  属性       | 说明        |  类型       |备注|
|  ----  | ----  |  ----  | ----  |
| Num  | 保留标识 |    Number  |   console.log()中的第一个参数，当第一个参数为Num时，该日志将被保留；不填则全不保留
| Env  | 保留环境 |    String |   "development" 或 "production"。填”development“时，开发环境下仅保留符合保留标识的日志语句，打包后的生产环境所有日志全保留；填”production“时同理相反；不填则不判断环境


### 示例 Examples

```js
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

```

---
_Source: https://npm.io/package/remove-unnecessary-console-vite · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
