{"id":22300,"library":"rollup-plugin","title":"rollup-plugin-clear-directory","description":"A Rollup plugin that clears the output directory before each build, ensuring a clean state and preventing leftover files from previous builds. Version 1.0.0 is the current stable release. It is a lightweight plugin with a simple configuration, allowing users to specify target directories to clear. The release cadence is low; no recent updates. Key differentiators: dedicated solely to clearing directories, unlike other plugins that bundle multiple utilities. Use with Rollup for build automation.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install rollup-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This plugin is a Rollup plugin and requires Rollup to function.","package":"rollup","optional":false}],"imports":[{"note":"The package exports a default function, so default import is correct. CommonJS require works but is not recommended for ESM projects.","wrong":"const clearDirectory = require('rollup-plugin-clear-directory');","symbol":"clearDirectory","correct":"import clearDirectory from 'rollup-plugin-clear-directory';"},{"note":"Named import does not work because the package uses default export.","wrong":"import { clearDirectory } from 'rollup-plugin-clear-directory';","symbol":"default","correct":"import clearDirectory from 'rollup-plugin-clear-directory';"},{"note":"TypeScript users can import the type for configuration. This is optional.","wrong":"","symbol":"ClearOptions","correct":"import type { ClearOptions } from 'rollup-plugin-clear-directory';"}],"quickstart":{"code":"// rollup.config.js\nimport clearDirectory from 'rollup-plugin-clear-directory';\n\nexport default {\n  input: 'src/main.js',\n  output: {\n    dir: 'dist',\n    format: 'esm'\n  },\n  plugins: [\n    clearDirectory({\n      targets: ['dist']\n    })\n  ]\n};","lang":"javascript","description":"Demonstrates basic usage of clearing the 'dist' directory before each Rollup build."},"warnings":[{"fix":"Ensure all target directories exist or handle errors. Alternatively, use a plugin like 'rollup-plugin-delete' which creates directories if needed.","message":"The plugin clears directories synchronously before bundling starts. If you specify a non-empty target that does not exist, it may throw.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Clear before build, not during. The plugin clears before the build hook, so it should be safe, but test with your configuration.","message":"If you target the output directory configured in Rollup output, the plugin may interfere with Rollup's own directory creation. Use with caution.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Create the directory before running the plugin or ensure the path is correct.","cause":"The target directory does not exist.","error":"Error: ENOENT: no such file or directory, rmdir '...'"},{"fix":"Use 'import clearDirectory from 'rollup-plugin-clear-directory';'","cause":"Incorrect import statement, e.g., using named import instead of default import.","error":"TypeError: clearDirectory is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}