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.

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.
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.
npm install esbuild-plugin-clear
yarn add esbuild-plugin-clear
pnpm add esbuild-plugin-clear

Shows basic usage: importing the clear plugin and passing the directory to clear before building.

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));