rollup-plugin-empty

raw JSON →
1.0.0 verified Mon Apr 27 auth: no javascript

A Rollup plugin for emptying directories or deleting files before a build. Version 1.0.0, stable. Differentiates by supporting both directory emptying and file deletion via fast-glob patterns, silent mode option for logging control. Useful for cleaning output directories as part of the build pipeline.

error TypeError: empty is not a function
cause Using named import instead of default import in ESM.
fix
Use import empty from 'rollup-plugin-empty'
error ENOENT: no such file or directory, unlink '...'
cause The file specified in 'file' option does not exist or already deleted.
fix
Ensure files exist at build start or use 'dir' option instead.
gotcha Using both `file` and `dir` options may lead to unintended behavior: files matching both patterns might be deleted and also the directory emptied.
fix Use either `file` or `dir` exclusively, or carefully design patterns to avoid overlap.
gotcha Glob patterns are resolved relative to the current working directory, not the config file location.
fix Use absolute paths or ensure cwd is correct.
deprecated Option 'silent' default changed from false to true in future versions; not yet deprecated but behavior may change.
fix Explicitly set 'silent' to desired value.
npm install rollup-plugin-empty
yarn add rollup-plugin-empty
pnpm add rollup-plugin-empty

Demonstrates emptying the 'dist' directory before building with Rollup.

import empty from 'rollup-plugin-empty';

export default {
  input: 'src/index.js',
  plugins: [
    empty({
      silent: false,
      dir: 'dist'
    })
  ],
  output: {
    dir: 'dist',
    format: 'es'
  }
};