UNPKG

2.08 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const chalk_1 = require("chalk");
4const formatWebpackMessages = require("react-dev-utils/formatWebpackMessages");
5const log = require("./log");
6const defaultOptions = {
7 // errors and warings will be logout by formatWebpackMessages
8 errors: false,
9 warnings: false,
10 colors: true,
11 assets: true,
12 chunks: false,
13 entrypoints: false,
14 modules: false,
15};
16const webpackStats = ({ urls, stats, statsOptions = defaultOptions, isFirstCompile }) => {
17 const statsJson = stats.toJson({
18 all: false,
19 errors: true,
20 warnings: true,
21 timings: true,
22 });
23 // compatible with webpack 5
24 ['errors', 'warnings'].forEach((jsonKey) => {
25 statsJson[jsonKey] = (statsJson[jsonKey] || []).map((item) => (item.message || item));
26 });
27 const messages = formatWebpackMessages(statsJson);
28 const isSuccessful = !messages.errors.length;
29 if (!process.env.DISABLE_STATS) {
30 log.info('WEBPACK', stats.toString(statsOptions));
31 if (isSuccessful) {
32 // @ts-ignore
33 if (stats.stats) {
34 log.info('WEBPACK', 'Compiled successfully');
35 }
36 else {
37 log.info('WEBPACK', `Compiled successfully in ${(statsJson.time / 1000).toFixed(1)}s!`);
38 }
39 if (isFirstCompile && urls) {
40 console.log();
41 log.info('WEBPACK', chalk_1.default.green('Starting the development server at:'));
42 log.info(' - Local : ', chalk_1.default.underline.white(urls.localUrlForBrowser));
43 log.info(' - Network: ', chalk_1.default.underline.white(urls.lanUrlForTerminal));
44 console.log();
45 }
46 }
47 else if (messages.errors.length) {
48 log.error('', messages.errors.join('\n\n'));
49 }
50 else if (messages.warnings.length) {
51 log.warn('', messages.warnings.join('\n\n'));
52 }
53 }
54 return isSuccessful;
55};
56exports.default = webpackStats;