Skip to content

Commit

Permalink
use rollup watch when in watch mode
Browse files Browse the repository at this point in the history
Fixes #72
  • Loading branch information
YonatanKra authored and jlmakes committed Nov 22, 2021
1 parent a6f5b78 commit de386a6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,20 @@ function createPreprocessor(preconfig, config, emitter, logger) {
options.output.dir = path.dirname(originalPath)
}

let bundle = await rollup.rollup(options)
cache.set(originalPath, bundle.cache)
let bundle;
options.cache = false;

if (watcher) {
const watch = await rollup.watch(options);
bundle = await new Promise(res => watch.on('event', ( { result, code }) => {
if (code === 'BUNDLE_END') return res(result);
}));

let [entry, ...dependencies] = bundle.watchFiles
watcher.add(entry, dependencies)
} else {
bundle = await rollup.rollup(options)
cache.set(originalPath, bundle.cache)
}

log.info('Generating bundle for ./%s', location)
Expand Down

0 comments on commit de386a6

Please sign in to comment.