rollup-plugin-del
raw JSON → 1.0.1 verified Mon Apr 27 auth: no javascript
A Rollup plugin that deletes specified files or directories before or after a build, commonly used to clean the output directory (e.g., dist). Version 1.0.1, last updated 2022. It wraps the `del` package to support glob patterns and automatically falls back to Rollup's output dir/file. Lightweight, no external plugin dependencies. Differentiates from @rollup/plugin-clean by offering glob flexibility and automatic output detection.
Common errors
error Error: Cannot find module 'del' ↓
cause Missing peer dependency `del`.
fix
Install del: npm install del --save-dev
error TypeError: del is not a function ↓
cause Using named import { del } instead of default import.
fix
Change to
import del from 'rollup-plugin-del' error Error: EACCES: permission denied, unlink '...' ↓
cause Attempting to delete files that the process does not have permissions for.
fix
Run with appropriate permissions or adjust file paths.
Warnings
gotcha Uses `del` under the hood which cannot delete the current working directory itself – avoid using dest: process.cwd() ↓
fix Specify a subdirectory like 'dist', not the root.
gotcha Plugin runs once on build start – not on watch rebuild. Files deleted during watch may cause errors. ↓
fix Restart Rollup after changes or consider other cleanup strategies.
gotcha The `del` peer dependency is not bundled; you must install `del` separately if not already present. ↓
fix Run `npm install del -D` alongside rollup-plugin-del.
Install
npm install rollup-plugin-del yarn add rollup-plugin-del pnpm add rollup-plugin-del Imports
- default wrong
import { del } from 'rollup-plugin-del'correctimport del from 'rollup-plugin-del' - default wrong
const del = require('rollup-plugin-del')correctconst del = require('rollup-plugin-del').default - default wrong
import del = require('rollup-plugin-del')correctimport del from 'rollup-plugin-del'
Quickstart
// rollup.config.js
import del from 'rollup-plugin-del';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
export default {
input: 'src/index.js',
output: {
dir: 'dist',
format: 'esm'
},
plugins: [
del(), // deletes dist before build
resolve(),
commonjs()
]
};