rollup-plugin-watch-globs
v2.0.1
Published
A Rollup plugin that allows you to watch arbitrary files for changes (like static assets and stylesheets)
Downloads
616
Readme
rollup-plugin-watch-globs
Copyright 2022, Caleb Evans
Released under the MIT License
By default, the rollup -w
command in Rollup only watches for changes to files
in the module graph of your input file (namely, JS/TS files). However, you may
have other static assets (like stylesheets or static HTML files) in your
project that should recompile your input when changed.
This plugin solves that problem by allowing you to watch any arbitrary file globs that should trigger Rollup's watch mechanism to recompile.
Setup
First, install it in your project like so:
npm install --save-dev rollup-plugin-watch-globs
Then, you can import it in your rollup.config.js
and specify it in your
plugins
array. The watchGlobs
function accepts an array of glob patterns to
watch.
import watchGlobs from 'rollup-plugin-watch-globs';
export default {
...
plugins: [
watchGlobs([
'public/**/*.*',
'src/styles/*.scss'
]),
// all your other plugins here...
]
}
This can be useful in conjunction with plugins like rollup-plugin-copy to watch for changes the same static files that you might copy to your build directory.
Attribution
This project was inspired by code written by @thekip for watching arbitrary file globs in Rollup.