rollup-plugin-watch-globs

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

A Rollup plugin that extends the watch mode to monitor arbitrary file globs (e.g., static assets, stylesheets, HTML) not in the module graph. Currently v2.0.1, maintained by Caleb Evans. Key differentiator: unlike relying on Rollup's default watch (which only tracks JS/TS files in the dependency graph), this plugin explicitly adds glob patterns to trigger rebuilds, complementing tools like rollup-plugin-copy. Released under MIT License, requires rollup >=2.0.0 as a peer dependency. A lightweight, focused solution with no runtime dependencies beyond rollup.

error TypeError: watchGlobs is not a function
cause Incorrect import style (CommonJS without .default or wrong ESM import).
fix
Use: import watchGlobs from 'rollup-plugin-watch-globs' (ESM) or const watchGlobs = require('rollup-plugin-watch-globs').default (CJS).
error Error: The 'watchGlobs' plugin hook 'watchChange' threw an error: Unexpected glob pattern
cause Passed a string instead of an array of strings.
fix
Wrap glob pattern in an array: watchGlobs(['public/**/*.*'])
gotcha Glob patterns must be provided as an array of strings, not an object or single string.
fix Ensure the argument is an array: watchGlobs(['**/*.css'])
gotcha This plugin only adds file watching; it does not handle actual copying or processing of watched files (use e.g., rollup-plugin-copy).
fix Combine with appropriate plugins for actions on change.
breaking v2.x changed the default export to be a callable function; previously it might have been a factory or object.
fix Use import watchGlobs from 'rollup-plugin-watch-globs' and call it directly.
npm install rollup-plugin-watch-globs
yarn add rollup-plugin-watch-globs
pnpm add rollup-plugin-watch-globs

Shows how to import and configure watchGlobs with two glob patterns to watch static assets and stylesheets.

// rollup.config.js
import watchGlobs from 'rollup-plugin-watch-globs';

export default {
  input: 'src/index.js',
  output: {
    dir: 'dist',
    format: 'esm'
  },
  plugins: [
    watchGlobs([
      'public/**/*.*',
      'src/styles/*.scss'
    ])
  ]
};