File tree Expand file tree Collapse file tree 1 file changed +20
-6
lines changed
Expand file tree Collapse file tree 1 file changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -14,18 +14,32 @@ const chalk = require('chalk');
1414
1515module . exports = function formatBuildError ( err ) {
1616 const message = get ( err , 'message' ) ;
17+ const stack = get ( err , 'stack' ) ;
1718
1819 // Add more helpful message for UglifyJs error
19- if ( typeof message === 'string' && message . indexOf ( 'from UglifyJs' ) !== - 1 ) {
20+ if (
21+ stack &&
22+ typeof message === 'string' &&
23+ message . indexOf ( 'from UglifyJs' ) !== - 1
24+ ) {
2025 try {
26+ const matched = / U n e x p e c t e d t o k e n : ( .+ ) \[ ( .+ ) \: ( .+ ) \, ( .+ ) \] \[ .+ \] / . exec (
27+ stack
28+ ) ;
29+ if ( ! matched ) {
30+ throw new Error (
31+ "The regex pattern is not matched. Maybe UglifyJs changed it's message?"
32+ ) ;
33+ }
34+ const problemPath = matched [ 2 ] ;
35+ const line = matched [ 3 ] ;
36+ const column = matched [ 4 ] ;
2137 console . log (
22- 'Failed to minify the code from \n\n' ,
23- chalk . yellow (
24- / U n e x p e c t e d t o k e n : ( .+ ) \[ ( .+ ) \] \[ ( .+ ) \] / . exec ( err . stack ) [ 2 ]
25- ) ,
38+ 'Failed to minify the code from this file: \n\n' ,
39+ chalk . yellow ( `${ problemPath } line ${ line } :${ column } ` ) ,
2640 '\n'
2741 ) ;
28- } catch ( e ) {
42+ } catch ( ignored ) {
2943 console . log ( 'Failed to minify the code.' , err ) ;
3044 }
3145 console . log (
You can’t perform that action at this time.
0 commit comments