Delete files and folders using Rollup
npm install rollup-plugin-deleteDelete files and folders using Rollup.
This plugin is useful when you want to clean dist or other folders and files before bundling. It's using del package inside, check it for pattern examples and additional options.
``bashpnpm
pnpm add rollup-plugin-delete -D
Usage
`js
// rollup.config.js
import del from 'rollup-plugin-delete'export default {
input: 'src/index.js',
output: {
file: 'dist/app.js'
},
plugins: [
del({ targets: 'dist' })
]
}
`$3
There are some useful options:
#### targets
A string or an array of patterns of files and folders to be deleted. Default is
[].`js
// Folder
del({
targets: 'build'
})// Files
del({
targets: 'dist/*.js'
})
// Multiple targets
del({
targets: ['dist/', 'images/.webp']
})
`#### verbose
Output removed files and folders to console. Default is
false.> [!NOTE]
> Use \* (wildcard character) in pattern to show removed files
`js
del({
targets: 'dist/*',
verbose: true
})
`#### hook
Rollup hook the plugin should use. Default is
buildStart.`js
del({
targets: 'dist/*',
hook: 'buildEnd'
})
`#### runOnce
Type:
boolean | Default: falseDelete items once. Useful in watch mode.
`js
del({
targets: 'dist/*',
runOnce: true
})
``All other options are passed to del package which is used inside.
MIT