UNPKG

rollup-plugin-watch

Version:

A rollup plugin to specify directories and files to watch

33 lines (29 loc) 859 B
'use strict'; var pluginutils = require('@rollup/pluginutils'); var fs = require('fs'); var path = require('path'); var process = require('process'); var index = (options = {}) => { const dir = options.dir; const filter = pluginutils.createFilter(options.include ?? [], options.exclude ?? []); return { name: "watch", buildStart() { const watch = (src) => { const filesToWatch = fs.readdirSync(src); for (let file of filesToWatch) { const fullPath = path.join(process.cwd(), src, file); const stats = fs.statSync(fullPath); if (!filter(fullPath)) continue; if (stats.isFile()) { this.addWatchFile(fullPath); } else if (stats.isDirectory()) { watch(fullPath); } } }; watch(dir); } }; }; module.exports = index;