forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch.mjs
47 lines (37 loc) · 1.12 KB
/
watch.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Watch files for changes and rebuild (copy from 'src/' to `build/`) if changed
*/
import chalk from 'chalk';
import webpack from 'webpack';
import {createWebpackConfigs} from './buildUtils.mjs';
const compiler = webpack(createWebpackConfigs());
let hasBuilt = false;
console.log(chalk.inverse(' Bundling packages '));
compiler.watch({}, (error, stats) => {
if (!hasBuilt) {
hasBuilt = true;
console.log(chalk.red('->'), chalk.cyan('Watching for changes…'));
}
if (error) {
console.error('Got error from watch mode', error);
}
if (stats) {
const info = stats.toJson();
if (stats.hasErrors() || stats.hasWarnings()) {
for (const error of info.errors) {
console.error('error', error.message);
}
for (const warning of info.warnings) {
console.warn('warning', warning.message);
}
} else {
console.log(chalk.red('->'), chalk.green('Rebuilt packages'));
}
}
});