Created
June 3, 2021 12:10
-
-
Save ba55ie/eaad5ccc74c665d52f1045fa5802e212 to your computer and use it in GitHub Desktop.
Rollup plugin copy watch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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