esbuild-plugin-clear
raw JSON → 1.0.1 verified Fri May 01 auth: no javascript
An esbuild plugin that clears a specified directory before each build. Version 1.0.0 is current, no known release cadence. It is a simple utility plugin that removes all files in the given directory path. Differentiates by being lightweight and dependency-free, unlike broader cleanup tools like rimraf or del integrated into build systems.
Common errors
error Error: Cannot find module 'esbuild-plugin-clear' ↓
cause Package not installed or installed as devDependency but not resolved.
fix
Run 'npm install --save-dev esbuild-plugin-clear' and ensure node_modules contains it.
Warnings
gotcha The plugin deletes the entire given directory contents recursively without confirmation. Ensure the path is correct. ↓
fix Double-check the directory path before running the build.
gotcha If the directory does not exist, the plugin may throw an error (depending on filesystem permissions). ↓
fix Ensure the target directory exists or handle the error gracefully.
Install
npm install esbuild-plugin-clear yarn add esbuild-plugin-clear pnpm add esbuild-plugin-clear Imports
- default (clear) wrong
const clear = require('esbuild-plugin-clear')correctimport clear from 'esbuild-plugin-clear' - clear as named import wrong
import { clear } from 'esbuild-plugin-clear'correctimport { default as clear } from 'esbuild-plugin-clear' - Used as plugin in esbuild wrong
clear({ path: './dist' })correctclear('./dist')
Quickstart
import esbuild from 'esbuild';
import clear from 'esbuild-plugin-clear';
esbuild.build({
entryPoints: ['./src/index.js'],
bundle: true,
outfile: './dist/index.js',
plugins: [
clear('./dist')
]
}).catch(() => process.exit(1));