diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index 486531ec99c42..57d3033778895 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -1,6 +1,6 @@ 'use strict'; -const {rollup} = require('rollup'); +const rollup = require('rollup'); const babel = require('rollup-plugin-babel'); const closure = require('./plugins/closure-plugin'); const commonjs = require('rollup-plugin-commonjs'); @@ -78,6 +78,7 @@ const requestedBundleTypes = argv.type : []; const requestedBundleNames = parseRequestedNames(argv._, 'lowercase'); const forcePrettyOutput = argv.pretty; +const isWatchMode = argv.watch; const syncFBSourcePath = argv['sync-fbsource']; const syncWWWPath = argv['sync-www']; const shouldExtractErrors = argv['extract-errors']; @@ -526,19 +527,42 @@ async function createBundle(bundle, bundleType) { bundleType ); - console.log(`${chalk.bgYellow.black(' BUILDING ')} ${logKey}`); - try { - const result = await rollup(rollupConfig); - await result.write(rollupOutputOptions); - } catch (error) { - console.log(`${chalk.bgRed.black(' OH NOES! ')} ${logKey}\n`); - handleRollupError(error); - throw error; - } - for (let i = 0; i < otherOutputPaths.length; i++) { - await asyncCopyTo(mainOutputPath, otherOutputPaths[i]); + if (isWatchMode) { + rollupConfig.output = [rollupOutputOptions]; + const watcher = rollup.watch(rollupConfig); + watcher.on('event', async event => { + switch (event.code) { + case 'BUNDLE_START': + console.log(`${chalk.bgYellow.black(' BUILDING ')} ${logKey}`); + break; + case 'BUNDLE_END': + for (let i = 0; i < otherOutputPaths.length; i++) { + await asyncCopyTo(mainOutputPath, otherOutputPaths[i]); + } + console.log(`${chalk.bgGreen.black(' COMPLETE ')} ${logKey}\n`); + break; + case 'ERROR': + case 'FATAL': + console.log(`${chalk.bgRed.black(' OH NOES! ')} ${logKey}\n`); + handleRollupError(event.error); + break; + } + }); + } else { + console.log(`${chalk.bgYellow.black(' BUILDING ')} ${logKey}`); + try { + const result = await rollup.rollup(rollupConfig); + await result.write(rollupOutputOptions); + } catch (error) { + console.log(`${chalk.bgRed.black(' OH NOES! ')} ${logKey}\n`); + handleRollupError(error); + throw error; + } + for (let i = 0; i < otherOutputPaths.length; i++) { + await asyncCopyTo(mainOutputPath, otherOutputPaths[i]); + } + console.log(`${chalk.bgGreen.black(' COMPLETE ')} ${logKey}\n`); } - console.log(`${chalk.bgGreen.black(' COMPLETE ')} ${logKey}\n`); } function handleRollupWarning(warning) {