rollup-plugin-watch-external
raw JSON → 1.0.2 verified Mon Apr 27 auth: no javascript
Rollup plugin to add additional files (e.g., assets, configs) to Rollup's watch list. Version 1.0.2 requires Rollup ^2.39.0. Minimal API: one option `entries` (array of glob patterns). Does not handle incremental rebuilds; simply triggers rebuild on changes to specified files. For a more feature-rich alternative, consider @rollup/plugin-watch or custom chokidar integration.
Common errors
error Error: Cannot find module 'rollup-plugin-watch-external' ↓
cause Package not installed or not in node_modules.
fix
Run
npm install rollup-plugin-watch-external --save-dev or yarn add -D rollup-plugin-watch-external. error TypeError: watchExternal is not a function ↓
cause Using default import instead of named import.
fix
Change to
import { watchExternal } from 'rollup-plugin-watch-external'. error Error: Rollup version mismatch: expected >=2.39.0, got 2.20.0 ↓
cause Installed Rollup version is too old.
fix
Update Rollup:
npm install rollup@latest --save-dev. Warnings
breaking Package requires Rollup ^2.39.0; incompatible with Rollup 1.x or early 2.x releases. ↓
fix Upgrade Rollup to at least 2.39.0 or use a different watch plugin.
gotcha The `entries` option uses glob patterns; if no files match, the plugin still adds the pattern but may not trigger builds. Ensure globs match existing files. ↓
fix Test your glob patterns (e.g., with `glob` package) before adding to plugin options.
Install
npm install rollup-plugin-watch-external yarn add rollup-plugin-watch-external pnpm add rollup-plugin-watch-external Imports
- watchExternal wrong
import watchExternal from 'rollup-plugin-watch-external'correctimport { watchExternal } from 'rollup-plugin-watch-external' - watchExternal wrong
const watchExternal = require('rollup-plugin-watch-external')correctconst { watchExternal } = require('rollup-plugin-watch-external') - watchExternal wrong
import * as watchExternal from 'rollup-plugin-watch-external'correctimport { watchExternal } from 'rollup-plugin-watch-external'
Quickstart
// rollup.config.js
import { watchExternal } from 'rollup-plugin-watch-external';
export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'iife'
},
plugins: [
watchExternal({
entries: ['public/**.js', 'data/*.json']
})
]
};