# esbuild-plugin-clean

> ESBuild plugin for cleaning up assets before building.

Latest version **1.0.1** (published 2022-11-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install esbuild-plugin-clean
pnpm add esbuild-plugin-clean
yarn add esbuild-plugin-clean
bun add esbuild-plugin-clean
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-11-21 |
| First published | 2021-05-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 14.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 118 |
| Author | Linbudu |
| Maintainers | linbudu |
| Keywords | esbuild, ESBuild, clean, plugin |

## Links

- npm: https://www.npmjs.com/package/esbuild-plugin-clean
- Repository: https://github.com/LinbuduLab/esbuild-plugins
- Homepage: https://github.com/LinbuduLab/esbuild-plugins/tree/master/packages/esbuild-plugin-clean#readme
- Issues: https://github.com/LinbuduLab/esbuild-plugins/issues
- npm.io page: https://npm.io/package/esbuild-plugin-clean

## Dependencies (2)

- [del](https://npm.io/package/del.md) ^6.0.0
- [chalk](https://npm.io/package/chalk.md) ^4.1.2

## 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.1 (latest) — 2022-11-21
- 1.0.0 — 2022-11-17
- 0.9.0 — 2022-03-12
- 0.8.0 — 2022-03-05
- 0.7.0 — 2022-03-05
- 0.6.0 — 2022-03-05
- 0.5.0 — 2021-09-20
- 0.4.0 — 2021-09-20
- 0.3.0 — 2021-09-20
- 0.2.0 — 2021-09-20
- 0.1.0 — 2021-09-20
- 0.1.3 — 2021-05-27
- 0.1.2 — 2021-05-20
- 0.1.1-1 — 2021-05-18
- 0.1.1-0 — 2021-05-16
- … 3 more at https://npm.io/package/esbuild-plugin-clean/versions

## README

# esbuild-plugin-clean

ESBuild plugin for cleaning up output/assets before building.

- [Author](https://github.com/linbudu599)
- [GitHub Repo](https://github.com/LinbuduLab/esbuild-plugins/tree/master/packages/esbuild-plugin-clean#readme)
- [Changelog](https://github.com/LinbuduLab/esbuild-plugins/blob/main/packages/esbuild-plugin-clean/CHANGELOG.md)

## Usage

```bash
npm install esbuild-plugin-clean --save-dev
pnpm install esbuild-plugin-clean --save-dev
yarn add esbuild-plugin-clean --save-dev
```

```typescript
import { build } from 'esbuild';
import { clean } from 'esbuild-plugin-clean';

(async () => {
  const res = await build({
    entryPoints: ['./demo.ts'],
    bundle: true,
    outfile: './dist/main.js',
    plugins: [
      clean({
        patterns: ['./dist/*', './dist/assets/*.map.js'],
        cleanOnStartPatterns: ['./prepare'],
        cleanOnEndPatterns: ['./post'],
      }),
    ],
  });
})();
```

## Configurations

This plugin use [del](https://www.npmjs.com/package/del) under the hood, so you can easily pass `del options` to this plugin.

```typescript
export interface CleanOptions {
  /**
   * file clean patterns (passed to `del`)
   *
   * @default: []
   */
  patterns?: string | string[];

  /**
   * file clean patterns(in onStart only) (passed to `del`)
   *
   * @default: []
   */
  cleanOnStartPatterns?: string | string[];

  /**
   * file clean patterns(in onEnd only) (passed to `del`)
   *
   * @default: []
   */
  cleanOnEndPatterns?: string | string[];

  /**
   * use dry-run mode to see what's going to happen
   *
   * this option will enable verbose option automatically
   *
   * @default: false
   */
  dryRun?: boolean;

  /**
   * extra options passed to `del`
   *
   * @default {}
   */
  options?: DelOptions;

  /**
   * execute clean sync or async (use `del` or `del.sync` for cleaning up)
   *
   * @default: true
   */
  sync?: boolean;

  /**
   * do cleaning in start / end / both
   * maybe in some strange cases you will need it ? :P
   *
   * @default: "start"
   */
  cleanOn?: 'start' | 'end' | 'both';

  /**
   * enable verbose logging to see what's happening
   *
   * @default false
   */
  verbose?: boolean;
}
```

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