rollup-plugin-clear

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

A Rollup plugin that clears specified directories before each build, useful for cleaning output folders before bundling. Current version: 2.0.7. Released under MIT. Lightweight, simple API with minimal configuration. Differentiators: no external dependencies, supports watch mode via option. Best for projects requiring a clean build output.

error TypeError: clear is not a function
cause Incorrect import: using require without .default
fix
Use const clear = require('rollup-plugin-clear').default;
error Cannot find module 'rollup-plugin-clear'
cause Plugin not installed or not listed in package.json
fix
Run npm install --save-dev rollup-plugin-clear
gotcha targets must be an array of strings, otherwise plugin may not work as expected.
fix Ensure targets is an array, e.g., targets: ['dist'].
gotcha Plugin only clears directories; it does not create them. Ensure the output directory exists or is created by Rollup.
fix Use another plugin like rollup-plugin-mkdirp or rely on Rollup's output.entryFileNames etc.
npm install rollup-plugin-clear
yarn add rollup-plugin-clear
pnpm add rollup-plugin-clear

Configures rollup-plugin-clear to clean the 'dist' directory before each build.

// rollup.config.js
import clear from 'rollup-plugin-clear';

export default {
  input: 'src/index.js',
  output: {
    dir: 'dist',
    format: 'esm'
  },
  plugins: [
    clear({
      targets: ['dist'],
      watch: false
    })
  ]
};