|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -const {rollup} = require('rollup'); |
| 3 | +const rollup = require('rollup'); |
4 | 4 | const babel = require('rollup-plugin-babel');
|
5 | 5 | const closure = require('./plugins/closure-plugin');
|
6 | 6 | const commonjs = require('rollup-plugin-commonjs');
|
@@ -78,6 +78,7 @@ const requestedBundleTypes = argv.type
|
78 | 78 | : [];
|
79 | 79 | const requestedBundleNames = parseRequestedNames(argv._, 'lowercase');
|
80 | 80 | const forcePrettyOutput = argv.pretty;
|
| 81 | +const isWatchMode = argv.watch; |
81 | 82 | const syncFBSourcePath = argv['sync-fbsource'];
|
82 | 83 | const syncWWWPath = argv['sync-www'];
|
83 | 84 | const shouldExtractErrors = argv['extract-errors'];
|
@@ -526,19 +527,42 @@ async function createBundle(bundle, bundleType) {
|
526 | 527 | bundleType
|
527 | 528 | );
|
528 | 529 |
|
529 |
| - console.log(`${chalk.bgYellow.black(' BUILDING ')} ${logKey}`); |
530 |
| - try { |
531 |
| - const result = await rollup(rollupConfig); |
532 |
| - await result.write(rollupOutputOptions); |
533 |
| - } catch (error) { |
534 |
| - console.log(`${chalk.bgRed.black(' OH NOES! ')} ${logKey}\n`); |
535 |
| - handleRollupError(error); |
536 |
| - throw error; |
537 |
| - } |
538 |
| - for (let i = 0; i < otherOutputPaths.length; i++) { |
539 |
| - await asyncCopyTo(mainOutputPath, otherOutputPaths[i]); |
| 530 | + if (isWatchMode) { |
| 531 | + rollupConfig.output = [rollupOutputOptions]; |
| 532 | + const watcher = rollup.watch(rollupConfig); |
| 533 | + watcher.on('event', async event => { |
| 534 | + switch (event.code) { |
| 535 | + case 'BUNDLE_START': |
| 536 | + console.log(`${chalk.bgYellow.black(' BUILDING ')} ${logKey}`); |
| 537 | + break; |
| 538 | + case 'BUNDLE_END': |
| 539 | + for (let i = 0; i < otherOutputPaths.length; i++) { |
| 540 | + await asyncCopyTo(mainOutputPath, otherOutputPaths[i]); |
| 541 | + } |
| 542 | + console.log(`${chalk.bgGreen.black(' COMPLETE ')} ${logKey}\n`); |
| 543 | + break; |
| 544 | + case 'ERROR': |
| 545 | + case 'FATAL': |
| 546 | + console.log(`${chalk.bgRed.black(' OH NOES! ')} ${logKey}\n`); |
| 547 | + handleRollupError(event.error); |
| 548 | + break; |
| 549 | + } |
| 550 | + }); |
| 551 | + } else { |
| 552 | + console.log(`${chalk.bgYellow.black(' BUILDING ')} ${logKey}`); |
| 553 | + try { |
| 554 | + const result = await rollup.rollup(rollupConfig); |
| 555 | + await result.write(rollupOutputOptions); |
| 556 | + } catch (error) { |
| 557 | + console.log(`${chalk.bgRed.black(' OH NOES! ')} ${logKey}\n`); |
| 558 | + handleRollupError(error); |
| 559 | + throw error; |
| 560 | + } |
| 561 | + for (let i = 0; i < otherOutputPaths.length; i++) { |
| 562 | + await asyncCopyTo(mainOutputPath, otherOutputPaths[i]); |
| 563 | + } |
| 564 | + console.log(`${chalk.bgGreen.black(' COMPLETE ')} ${logKey}\n`); |
540 | 565 | }
|
541 |
| - console.log(`${chalk.bgGreen.black(' COMPLETE ')} ${logKey}\n`); |
542 | 566 | }
|
543 | 567 |
|
544 | 568 | function handleRollupWarning(warning) {
|
|
0 commit comments