1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | const chalk = require('chalk')
|
8 | const TYPE = 'cant-resolve-loader'
|
9 | const errorRE = /Can't resolve '(.*loader)'/
|
10 |
|
11 | exports.transformer = error => {
|
12 | if (error.webpackError && error.webpackError.message) {
|
13 | const match = error.webpackError.message.match(errorRE)
|
14 | if (match) {
|
15 | return Object.assign({}, error, {
|
16 | type: TYPE,
|
17 | loader: match[1]
|
18 | })
|
19 | }
|
20 | }
|
21 | return error
|
22 | }
|
23 |
|
24 | exports.formatter = errors => {
|
25 | errors = errors.filter(e => e.type === TYPE)
|
26 | if (errors.length) {
|
27 | return errors
|
28 | .map(e => {
|
29 | return `Failed to resolve loader: ${chalk.yellow(e.loader)}`
|
30 | })
|
31 | .concat(`\nYou may need to install the missing loader.`)
|
32 | }
|
33 | }
|