rollup-plugin-watch

raw JSON →
1.0.5 verified Mon Apr 27 auth: no javascript

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).

error Error: Cannot find module 'rollup-plugin-watch'
cause Package not installed or wrong import path.
fix
Run npm install rollup-plugin-watch --save-dev and ensure the import uses default import.
error TypeError: watch is not a function
cause Using named import { watch } instead of default import.
fix
Change import to: import watch from 'rollup-plugin-watch'.
error The watch option 'dir' must be a string
cause Passing a non-string value (e.g., array or object) to dir.
fix
Set dir to a single directory path as a string: dir: 'public'.
gotcha The `dir` option does not recursively watch subdirectories by default; you must use `include` with glob patterns for deeper watches.
fix Set include: ['**/*'] to watch all files recursively within the directory.
deprecated Options `include` and `exclude` were originally strings; array support added later. Using a string still works but is deprecated in favor of arrays.
fix Use arrays: include: ['file1', 'file2'] instead of include: 'file1'.
gotcha This plugin only notifies Rollup to watch files; it does not trigger builds on file changes outside Rollup's watch mode.
fix Ensure Rollup is running in watch mode (e.g., rollup -w) for the plugin to have any effect.
gotcha The plugin has no effect on builds (non-watch mode); it is solely for development with Rollup's watcher.
fix Only use in development configurations; do not expect it to work in build-only scripts.
npm install rollup-plugin-watch
yarn add rollup-plugin-watch
pnpm add rollup-plugin-watch

Shows basic usage: watch a directory with include/exclude patterns for non-imported assets.

import watch from 'rollup-plugin-watch';

export default {
  input: 'index.js',
  output: { file: 'dist/index.js', format: 'esm' },
  plugins: [
    watch({
      dir: 'public',
      include: ['**/*.html', '**/*.css'],
      exclude: ['node_modules/**']
    })
  ]
};