{"id":22286,"library":"rollup-plugin-watch","title":"rollup-plugin-watch","description":"A Rollup plugin to specify additional directories and files for Rollup to watch during dev mode, complementing Rollup's built-in watch mechanism. Version 1.0.5 (stable) requires Node >=16 and peer dependency rollup ^2.x.x || ^3.x.x || ^4.x.x. It ships TypeScript definitions. Key differentiator: allows watching external assets not imported in code, preventing unnecessary dev server restarts. Low maintenance, minimal API surface (dir, include, exclude).","status":"active","version":"1.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/jleeson/rollup-plugin-watch","tags":["javascript","rollup","rollup-plugin","watch","directories","files","assets","typescript"],"install":[{"cmd":"npm install rollup-plugin-watch","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-watch","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-watch","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for plugin to work","package":"rollup","optional":false}],"imports":[{"note":"Package uses default export; named export does not exist","wrong":"import { watch } from 'rollup-plugin-watch'","symbol":"default (watch function)","correct":"import watch from 'rollup-plugin-watch'"},{"note":"CJS works with default export","wrong":"const { watch } = require('rollup-plugin-watch')","symbol":"CommonJS require","correct":"const watch = require('rollup-plugin-watch')"},{"note":"Types are exported but not as runtime values; use type-only import","wrong":"import { RollupWatchOptions } from 'rollup-plugin-watch'","symbol":"TypeScript type import","correct":"import type { RollupWatchOptions } from 'rollup-plugin-watch'"}],"quickstart":{"code":"import watch from 'rollup-plugin-watch';\n\nexport default {\n  input: 'index.js',\n  output: { file: 'dist/index.js', format: 'esm' },\n  plugins: [\n    watch({\n      dir: 'public',\n      include: ['**/*.html', '**/*.css'],\n      exclude: ['node_modules/**']\n    })\n  ]\n};","lang":"typescript","description":"Shows basic usage: watch a directory with include/exclude patterns for non-imported assets."},"warnings":[{"fix":"Set include: ['**/*'] to watch all files recursively within the directory.","message":"The `dir` option does not recursively watch subdirectories by default; you must use `include` with glob patterns for deeper watches.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use arrays: include: ['file1', 'file2'] instead of include: 'file1'.","message":"Options `include` and `exclude` were originally strings; array support added later. Using a string still works but is deprecated in favor of arrays.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Ensure Rollup is running in watch mode (e.g., rollup -w) for the plugin to have any effect.","message":"This plugin only notifies Rollup to watch files; it does not trigger builds on file changes outside Rollup's watch mode.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Only use in development configurations; do not expect it to work in build-only scripts.","message":"The plugin has no effect on builds (non-watch mode); it is solely for development with Rollup's watcher.","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":"Run npm install rollup-plugin-watch --save-dev and ensure the import uses default import.","cause":"Package not installed or wrong import path.","error":"Error: Cannot find module 'rollup-plugin-watch'"},{"fix":"Change import to: import watch from 'rollup-plugin-watch'.","cause":"Using named import { watch } instead of default import.","error":"TypeError: watch is not a function"},{"fix":"Set dir to a single directory path as a string: dir: 'public'.","cause":"Passing a non-string value (e.g., array or object) to dir.","error":"The watch option 'dir' must be a string"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}