diff --git a/lib/index.js b/lib/index.js index 11de89c..b1a9846 100644 --- a/lib/index.js +++ b/lib/index.js @@ -7,7 +7,11 @@ const Watcher = require("./Watcher"); function createPreprocessor(preconfig, config, emitter, logger) { const cache = new Map(); const log = logger.create("preprocessor.rollup"); - const watcher = new Watcher(emitter); + + let watcher; + if (!config.singleRun && config.autoWatch) { + watcher = new Watcher(emitter); + } return async function preprocess(original, file, done) { const location = path.relative(config.basePath, file.path); @@ -25,8 +29,10 @@ function createPreprocessor(preconfig, config, emitter, logger) { const bundle = await rollup.rollup(options); cache.set(file.path, bundle.cache); - const [entry, ...dependencies] = bundle.watchFiles; - watcher.add(entry, dependencies); + if (watcher) { + const [entry, ...dependencies] = bundle.watchFiles; + watcher.add(entry, dependencies); + } log.info("Generating bundle for ./%s", location); const { output } = await bundle.generate(options);