1 |
|
2 |
|
3 | const chalk = require('chalk');
|
4 | const printBuildError = require('react-dev-utils/printBuildError');
|
5 | const build = require('./build-wrapper');
|
6 | const { calculateAssetsSizes, printAssetsSizes } = require('../util/client-assets-sizes');
|
7 | const config = require('../../configs/webpack.client.prod');
|
8 |
|
9 | console.log(chalk.magenta('Building client...'));
|
10 |
|
11 | build(config)
|
12 | .then(({ stats, warnings }) => {
|
13 | if (warnings.length) {
|
14 | console.log(chalk.yellow('Client compiled with warnings.\n'));
|
15 | console.log(warnings.join('\n\n'));
|
16 | console.log(
|
17 | `Search for the ${chalk.underline(chalk.yellow('keywords'))} to learn more about each warning.`
|
18 | );
|
19 | console.log(
|
20 | `To ignore, add ${chalk.cyan('// eslint-disable-next-line')} to the line before.`
|
21 | );
|
22 | } else {
|
23 | console.log(chalk.green('Client compiled successfully.\n'));
|
24 | }
|
25 |
|
26 | function printOutputSizes(webpackConfig) {
|
27 | const sizes = calculateAssetsSizes(stats, webpackConfig.output.path);
|
28 | printAssetsSizes(sizes);
|
29 | }
|
30 |
|
31 | if (Array.isArray(config)) {
|
32 | config.forEach(printOutputSizes)
|
33 | } else {
|
34 | printOutputSizes(config);
|
35 | }
|
36 | })
|
37 | .catch((err) => {
|
38 | console.log(chalk.red('Failed to compile client.\n'));
|
39 | printBuildError(err);
|
40 | process.exit(1);
|
41 | });
|