esbuild-plugin-output-reset

raw JSON →
2.0.2 verified Fri May 01 auth: no javascript

ESBuild plugin that automatically clears the output directory before each build, ensuring a clean build state by removing old files. Version 2.0.2 is the current stable release, with no recent updates. It is a lightweight, single-purpose plugin that integrates seamlessly with ESBuild's plugin system. Unlike manual cleanup scripts, it runs as part of the ESBuild build process and respects the configured outdir or outfile paths. Ships with TypeScript type definitions.

error TypeError: clear is not a function
cause Using named import instead of default import in ES module context.
fix
Change import { clear } from 'esbuild-plugin-output-reset' to import clear from 'esbuild-plugin-output-reset'.
error Error: The plugin 'esbuild-plugin-output-reset' must be a function, object, or a promise resolving to one.
cause In older ESBuild versions (<0.17), plugins needed to be objects. The plugin is a function that returns an object.
fix
Upgrade esbuild to version 0.17 or later.
error Error: Cannot find module 'esbuild-plugin-output-reset'
cause Package not installed or not in node_modules.
fix
Run npm install esbuild-plugin-output-reset --save-dev (or your package manager equivalent).
gotcha The plugin deletes the entire output directory specified by outdir or outfile's parent directory. If you have other important files in that directory, they will be removed.
fix Ensure the output directory is dedicated solely to the build output.
gotcha The plugin will not work if both outdir and outfile are undefined; it will throw an error as there is no output path to reset.
fix Always specify either outdir or outfile in your ESBuild options.
breaking In version 2.0.0, the plugin changed to be an async function that returns a plugin object. Previously it was a direct plugin object.
fix If using older version, update the import and usage: the plugin is now used as import clear from 'esbuild-plugin-output-reset' and passed directly to plugins array.
deprecated Version 1.x used a named export 'clear'. In version 2.x it was replaced with a default export.
fix Switch to default import: import clear from 'esbuild-plugin-output-reset'.
npm install esbuild-plugin-output-reset
yarn add esbuild-plugin-output-reset
pnpm add esbuild-plugin-output-reset

Shows the minimal setup to use the plugin with ESBuild's build API, cleaning the dist folder before each build.

import esbuild from 'esbuild';
import clear from 'esbuild-plugin-output-reset';

await esbuild.build({
  entryPoints: ['./src/index.js'],
  bundle: true,
  outdir: './dist',
  plugins: [clear],
});