@@ -7,6 +7,9 @@ const delve = require('dlv');
77// @see https://github.com/sindresorhus/import-cwd
88const importCwd = require ( 'import-cwd' ) ;
99
10+ // @see https://github.com/chalk/chalk
11+ const chalk = require ( 'chalk' ) ;
12+
1013// @see https://github.com/shellscape/webpack-log
1114const log = ( new require ( 'webpack-log' ) ) ( { name : 'build' } ) ;
1215
@@ -34,23 +37,42 @@ const fn = (args = [], flags = {}) => {
3437 return dump . fn ( webpackConfig , path . join ( process . cwd ( ) , config ) ) ;
3538 }
3639
37- try {
38- webpack ( webpackConfig ) . run ( ( e , stats ) => {
39- if ( e ) {
40- process . exitCode = 1 ;
40+ log . info ( chalk `Running in {bold production} mode…` ) ;
4141
42- return log . error ( e ) ;
43- }
42+ // @see https://webpack.js.org/api/node/
43+ const compiler = webpack ( webpackConfig , ( error , stats ) => {
44+ if ( stats . hasErrors ( ) === false && ( error === undefined || error === null ) ) {
45+ log . info ( stats . toString ( webpackConfig . stats ) ) ;
46+ log . info ( 'Build complete.' ) ;
47+
48+ return ;
49+ }
4450
45- console . log (
46- stats . toString ( webpackConfig . stats )
47- ) ;
48- } ) ;
49- } catch ( e ) {
5051 process . exitCode = 1 ;
5152
52- log . error ( e ) ;
53- }
53+ // Fatal webpack errors (wrong configuration, etc)
54+ if ( error ) {
55+ log . error ( error . stack || error ) ;
56+
57+ if ( error . details ) {
58+ log . error ( error . details )
59+ }
60+
61+ return ;
62+ }
63+
64+ // Compilation errors (missing modules, syntax errors, etc)
65+ if ( stats . hasErrors ( ) ) {
66+ log . error ( stats . toString ( webpackConfig . stats ) ) ;
67+ }
68+
69+ // Compilation warnings
70+ if ( stats . hasWarnings ( ) ) {
71+ log . warn ( stats . toString ( webpackConfig . stats ) ) ;
72+ }
73+
74+ log . info ( 'Build incomplete.' ) ;
75+ } ) ;
5476} ;
5577
5678module . exports = {
0 commit comments