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.
Common errors
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 Warnings
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.
Install
npm install rollup-plugin-clear yarn add rollup-plugin-clear pnpm add rollup-plugin-clear Imports
- default (clear) wrong
const { default: clear } = require('rollup-plugin-clear')correctimport clear from 'rollup-plugin-clear' - default (clear) wrong
const clear = require('rollup-plugin-clear');correctconst clear = require('rollup-plugin-clear').default; - TypeScript type wrong
import { Options } from 'rollup-plugin-clear'correctimport type { Options } from 'rollup-plugin-clear'
Quickstart
// 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
})
]
};