mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
add --watch mode to "yarn build" (#15116)
* wip: add --watch mode to "yarn build" * fix: handle error events
This commit is contained in:
committed by
Christoph Nakazawa
parent
793ef9b855
commit
ed36df46c6
@@ -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;
|
||||
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`);
|
||||
}
|
||||
for (let i = 0; i < otherOutputPaths.length; i++) {
|
||||
await asyncCopyTo(mainOutputPath, otherOutputPaths[i]);
|
||||
}
|
||||
console.log(`${chalk.bgGreen.black(' COMPLETE ')} ${logKey}\n`);
|
||||
}
|
||||
|
||||
function handleRollupWarning(warning) {
|
||||
|
||||
Reference in New Issue
Block a user