|
2 | 2 |
|
3 | 3 | [](https://travis-ci.org/geowarin/friendly-errors-webpack-plugin)
|
4 | 4 |
|
5 |
| -Not ready yet. See [this](https://github.com/facebookincubator/create-react-app/issues/401) |
6 |
| -and [this](https://github.com/geowarin/tarec/pull/16) for more context. |
| 5 | +Friendly-errors-webpack-plugin recognizes certain classes of webpack |
| 6 | +errors and cleans, aggregates and prioritizes them to provide a better |
| 7 | +Developer Experience. |
| 8 | + |
| 9 | +It is easy to add types of errors so if you would like to see more |
| 10 | +errors get handled, please open a [PR](https://help.github.com/articles/creating-a-pull-request/)! |
| 11 | + |
| 12 | +## Demo |
| 13 | + |
| 14 | +### Build success |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +### eslint-loader errors |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +### babel-loader syntax errors |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +### Module not found |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +## Options |
| 31 | + |
| 32 | +You can pass options to the plugin: |
| 33 | + |
| 34 | +```js |
| 35 | +new FriendlyErrorsPlugin({ |
| 36 | + compilationSuccessInfo: { |
| 37 | + messages: ['You application is running here http://localhost:3000'], |
| 38 | + notes: ['Some additionnal notes to be displayed unpon successful compilation'] |
| 39 | + }, |
| 40 | + onErrors: function (severity, errors) { |
| 41 | + // You can listen to errors transformed and prioritized by the plugin |
| 42 | + // sevrity can be 'error' or 'warning' |
| 43 | + }, |
| 44 | + // should the console be cleared between each compilation? |
| 45 | + // default is true |
| 46 | + shouldClearConsole: true, |
| 47 | + |
| 48 | + // add formatters and transformers (see below) |
| 49 | + additionalFormatters: [], |
| 50 | + additionalTransformers: [] |
| 51 | +}) |
| 52 | +``` |
| 53 | + |
| 54 | +## Adding desktop notifications |
| 55 | + |
| 56 | +The plugin has no native support for desktop notifications but it is easy |
| 57 | +to add them thanks to [node-notifier](https://www.npmjs.com/package/node-notifier) for instance. |
| 58 | + |
| 59 | +```js |
| 60 | +var NotifierPlugin = require('friendly-errors-webpack-plugin'); |
| 61 | +var notifier = require('node-notifier'); |
| 62 | +var ICON = path.join(__dirname, 'icon.png'); |
| 63 | + |
| 64 | +new NotifierPlugin({ |
| 65 | + onErrors: (severity, errors) => { |
| 66 | + if (severity !== 'error') { |
| 67 | + return; |
| 68 | + } |
| 69 | + const error = errors[0]; |
| 70 | + notifier.notify({ |
| 71 | + title: context.pkg.name, |
| 72 | + message: severity + ': ' + error.name, |
| 73 | + subtitle: error.file || '', |
| 74 | + icon: ICON |
| 75 | + }); |
| 76 | + } |
| 77 | + }) |
| 78 | +] |
| 79 | +``` |
| 80 | + |
| 81 | +## API |
| 82 | + |
| 83 | +### Transformers and formatters |
| 84 | + |
| 85 | +Webpack's errors processing, is done in four phases: |
| 86 | + |
| 87 | +1. Extract relevant info from webpack errors. This is done by the plugin [here](https://github.com/geowarin/friendly-errors-webpack-plugin/blob/master/src/core/extractWebpackError.js) |
| 88 | +2. Apply transformers to all errors to identify and annotate well know errors and give them a priority |
| 89 | +3. Get only top priority error or top priority warnings if no errors are thrown |
| 90 | +4. Apply formatters to all annotated errors |
| 91 | + |
| 92 | +You can add transformers and formatters. Please see [transformErrors](https://github.com/geowarin/friendly-errors-webpack-plugin/blob/master/src/core/transformErrors.js), |
| 93 | +and [formatErrors](https://github.com/geowarin/friendly-errors-webpack-plugin/blob/master/src/core/formatErrors.js) |
| 94 | +in the source code and take a look a the [default transformers](https://github.com/geowarin/friendly-errors-webpack-plugin/tree/master/src/transformers) |
| 95 | +and the [default formatters](https://github.com/geowarin/friendly-errors-webpack-plugin/tree/master/src/formatters). |
7 | 96 |
|
8 | 97 | ## TODO
|
9 | 98 |
|
|
0 commit comments