# esbuild-clean-plugin

> An esbuild plugin to clean your build folder.

Latest version **2.1.4** (published 2026-08-05) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.1.4 |
| Published | 2026-08-05 |
| First published | 2021-05-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=22.11.0 |
| Dependencies | 1 |
| Unpacked size | 11.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 7 |
| Author | Jonathan Wilsson |
| Maintainers | jwilsson |
| Keywords | esbuild, plugin, clean |

## Links

- npm: https://www.npmjs.com/package/esbuild-clean-plugin
- Repository: https://github.com/jwilsson/esbuild-clean-plugin
- Homepage: https://github.com/jwilsson/esbuild-clean-plugin#readme
- Issues: https://github.com/jwilsson/esbuild-clean-plugin/issues
- npm.io page: https://npm.io/package/esbuild-clean-plugin

## Dependencies (1)

- [del](https://npm.io/package/del.md) ^8.0.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

- 2.1.4 (latest) — 2026-08-05
- 2.1.3 — 2026-08-05
- 2.1.2 — 2026-07-18
- 2.0.0 — 2025-02-15
- 1.0.0 — 2021-05-15

## README

# esbuild-clean-plugin
[![npm](https://img.shields.io/npm/v/esbuild-clean-plugin.svg)](https://www.npmjs.com/package/esbuild-clean-plugin)
[![build](https://github.com/jwilsson/esbuild-clean-plugin/actions/workflows/build.yml/badge.svg)](https://github.com/jwilsson/esbuild-clean-plugin/actions/workflows/build.yml)

An [esbuild](https://esbuild.github.io/) plugin to clean your build folder.

## Installation
```sh
npm install esbuild-clean-plugin
```

### Requirements
* Node 22.11.0 (LTS) or later.
* esbuild 0.18.20 or later.

## Usage
```js
import * as esbuild from 'esbuild';
import { cleanPlugin } from 'esbuild-clean-plugin';
import path from 'node:path';

const context = await esbuild.context({
  bundle: true,
  entryPoints: [path.resolve(import.meta.dirname, 'index.js')],
  metafile: true,
  outdir: path.resolve(import.meta.dirname, 'dist'),
  plugins: [cleanPlugin({
      // Plugin options
  })],
});

await context.watch();
```

*Note: The `metafile` and `outdir` options must be set for the plugin to have any effect.*

### Options
* `dry` (default `false`) - Run the plugin in dry mode, not deleting anything. Most useful together with the `verbose` option to see what would have been deleted.
* `initialCleanPatterns` (default `['**/*']`) - File patterns to remove on plugin setup, useful to clean the build directory before creating new files. Pass an empty array to disable it.
* `verbose` (default `false`) - Print all files that have been deleted after each run.

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