Skip to content

Instantly share code, notes, and snippets.

@ba55ie
Created June 3, 2021 12:10
Show Gist options
  • Save ba55ie/eaad5ccc74c665d52f1045fa5802e212 to your computer and use it in GitHub Desktop.
Save ba55ie/eaad5ccc74c665d52f1045fa5802e212 to your computer and use it in GitHub Desktop.
Rollup plugin copy watch
import * as chokidar from 'chokidar';
import copy from 'rollup-plugin-copy';
import { red } from 'colorette';
export default function copyWatch(options = {}) {
const {
hook = 'buildEnd',
watch = false,
} = options;
if (!watch) {
console.log(red('[rollup-plugin-copy-watch]: "watch" option not set. Returning the default "rollup-plugin-copy" plugin'));
return copy(options);
}
const {
[hook]: doCopy,
} = copy(options);
chokidar
.watch(watch, {
ignoreInitial: true,
})
.on('all', doCopy);
return {
name: 'copy+watch',
[hook]: doCopy,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment