1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict'
|
11 |
|
12 | const chalk = require('chalk')
|
13 |
|
14 | module.exports = function printBuildError(err) {
|
15 | const message = err != null && err.message
|
16 | const stack = err != null && err.stack
|
17 |
|
18 |
|
19 | if (typeof message === 'string' && message.indexOf(`Can't resolve`) > -1) {
|
20 | const matched = message.match(/Can't resolve '(.*loader)'/)
|
21 |
|
22 | if (matched) {
|
23 | console.log(`Failed to resolve loader: ${chalk.yellow(matched[1])}\n`)
|
24 | console.log('You may need to install the missing loader.\n')
|
25 | return
|
26 | }
|
27 | }
|
28 |
|
29 |
|
30 | if (
|
31 | stack &&
|
32 | typeof message === 'string' &&
|
33 | message.indexOf('from UglifyJs') !== -1
|
34 | ) {
|
35 | try {
|
36 | const matched = /(.+)\[(.+):(.+),(.+)\]\[.+\]/.exec(stack)
|
37 | if (!matched) {
|
38 | throw new Error('Using errors for control flow is bad.')
|
39 | }
|
40 | const problemPath = matched[2]
|
41 | const line = matched[3]
|
42 | const column = matched[4]
|
43 | console.log(
|
44 | 'Failed to minify the code from this file: \n\n',
|
45 | chalk.yellow(
|
46 | `\t${problemPath}:${line}${column !== '0' ? ':' + column : ''}`
|
47 | ),
|
48 | '\n'
|
49 | )
|
50 | } catch (ignored) {
|
51 | console.log('Failed to minify the bundle.', err)
|
52 | }
|
53 | console.log('Read more here: http://bit.ly/CRA-build-minify')
|
54 | } else {
|
55 | console.log((message || err) + '\n')
|
56 | }
|
57 | console.log()
|
58 | }
|