rollup-plugin-cleandir
raw JSON → 3.0.0 verified Mon Apr 27 auth: no javascript
A Rollup plugin that automatically empties output directories before each build. Version 3.0.0 requires Rollup >=4.0.0 and runs on the `buildStart` hook with `order: 'pre'` by default, ensuring cleanup happens before any other plugin. The plugin forces an explicit `OUT_DIR` argument (optional in v2 but required in v3). It ships TypeScript definitions. Compared to similar plugins like `rollup-plugin-clean`, it is minimal and focused, with no extra features. Release cadence is low; major versions align with Rollup major upgrades.
Common errors
error Cannot find module 'rollup-plugin-cleandir' ↓
cause Missing installation or incorrect import style.
fix
Install the package:
npm install --save-dev rollup-plugin-cleandir and use named import: import { cleandir } from 'rollup-plugin-cleandir'. error TypeError: cleandir is not a function ↓
cause Using default import or wrong import style.
fix
Use named import:
import { cleandir } from 'rollup-plugin-cleandir' error Error: OUT_DIR is required ↓
cause cleandir() called without arguments in v3.0.0.
fix
Pass the output directory path as the first argument:
cleandir('dist'). Warnings
breaking OUT_DIR is now required in v3.0.0 ↓
fix Always pass the output directory path as the first argument to cleandir().
breaking v2.0.0 requires Rollup >=2.0.0 ↓
fix Upgrade Rollup to v2 or higher, or stay on v1.x of the plugin.
gotcha Plugin uses `buildStart` hook with `order:'pre'`; may run before other plugins that also use the same hook with `order:'pre'` ↓
fix If you need a different ordering, use the options argument to specify a custom hook and/or order.
Install
npm install rollup-plugin-cleandir yarn add rollup-plugin-cleandir pnpm add rollup-plugin-cleandir Imports
- cleandir wrong
import cleandir from 'rollup-plugin-cleandir'correctimport { cleandir } from 'rollup-plugin-cleandir' - cleandir (CommonJS) wrong
const cleandir = require('rollup-plugin-cleandir').defaultcorrectconst { cleandir } = require('rollup-plugin-cleandir') - type CleandirOptions
import type { CleandirOptions } from 'rollup-plugin-cleandir'
Quickstart
// rollup.config.js
import { cleandir } from 'rollup-plugin-cleandir';
export default {
input: 'src/index.js',
output: {
dir: 'dist',
format: 'es',
},
plugins: [cleandir('dist')],
};