# dead-code-plugin

> ### 平台兼容

Latest version **0.2.2** (published 2024-08-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install dead-code-plugin
pnpm add dead-code-plugin
yarn add dead-code-plugin
bun add dead-code-plugin
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2024-08-31 |
| First published | 2024-01-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14 |
| Dependencies | 13 |
| Unpacked size | 256 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | guilin.li |
| Maintainers | guilinli |
| Keywords | deadcode, unused code, unused files, webpack plugin, vite plugin |

## Links

- npm: https://www.npmjs.com/package/dead-code-plugin
- npm.io page: https://npm.io/package/dead-code-plugin

## Dependencies (13)

- [ora](https://npm.io/package/ora.md) ^5.3.0
- [chalk](https://npm.io/package/chalk.md) ^4.1.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [fast-glob](https://npm.io/package/fast-glob.md) ^3.3.2
- [lodash-es](https://npm.io/package/lodash-es.md) ^4.17.21
- [minimatch](https://npm.io/package/minimatch.md) ^3.1.2
- [typescript](https://npm.io/package/typescript.md) ^5.3.3
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.23.7
- [@types/node](https://npm.io/package/@types/node.md) ^20.10.4
- [@babel/parser](https://npm.io/package/@babel/parser.md) ^7.22.4
- [@vue/compiler-dom](https://npm.io/package/@vue/compiler-dom.md) ^3.3.13
- [flow-remove-types](https://npm.io/package/flow-remove-types.md) ^2.229.2
- [@typescript-eslint/typescript-estree](https://npm.io/package/@typescript-eslint/typescript-estree.md) 7.1.0

## 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

- 0.2.2 (latest) — 2024-08-31
- 0.2.1 — 2024-03-30
- 0.2.0 — 2024-03-09
- 0.1.1 — 2024-01-21
- 0.1.0 — 2024-01-20

## README

## dead-code-plugin 插件

### 平台兼容

同时支持多个打包平台，基于 rollup 插件系统的都可以使用

- webpack
- vite
- rollup

### 参数配置

```ts
export type IOptions = {
  /** 指定项目的打包器 */
  bundler: 'vite' | 'webpack' | 'rollup';
  /** 需要校验的文件 */
  patterns: string[];
  /** 需要排除的文件 */
  exclude: string[];
  /** 是否检测未使用的文件 */
  detectUnusedFiles?: boolean;
  /** 是否检测未使用的导出 */
  detectUnusedExport?: boolean;
  /** 导出为json */
  exportJSON?: boolean;
  /** 检测命中时结束进程 @default false */
  failOnHint?: boolean;
  /** console.log输出检测  */
  log?: string;
  /** 项目预设 */
  preset?: 'node' | 'next' | 'vue' | 'react-native';
};
```

**_如果 webpack 模式无法检测未使用的变量请使用开发模式_**

```js
{
  mode: 'development',
  optimization: {
    usedExports: true, // 对无用的代码进行标记
  }
}
```

**_如果 vite rollup 模式无法检测未使用的变量请使用 vite build 运行打包流程_**

**_`namespace`会被检测为未被使用的对象需要忽略_**

[参考文献](https://cloud.tencent.com/developer/article/1874647)

---
_Source: https://npm.io/package/dead-code-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
