friendly-errors-webpack-plugin

WebJar for friendly-errors-webpack-plugin

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

friendly-errors-webpack-plugin
Last Version

Last Version

1.7.0
Release Date

Release Date

Type

Type

jar
Description

Description

friendly-errors-webpack-plugin
WebJar for friendly-errors-webpack-plugin
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/geowarin/friendly-errors-webpack-plugin

Download friendly-errors-webpack-plugin

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/friendly-errors-webpack-plugin/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>friendly-errors-webpack-plugin</artifactId>
    <version>1.7.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/friendly-errors-webpack-plugin/
implementation 'org.webjars.npm:friendly-errors-webpack-plugin:1.7.0'
// https://jarcasting.com/artifacts/org.webjars.npm/friendly-errors-webpack-plugin/
implementation ("org.webjars.npm:friendly-errors-webpack-plugin:1.7.0")
'org.webjars.npm:friendly-errors-webpack-plugin:jar:1.7.0'
<dependency org="org.webjars.npm" name="friendly-errors-webpack-plugin" rev="1.7.0">
  <artifact name="friendly-errors-webpack-plugin" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='friendly-errors-webpack-plugin', version='1.7.0')
)
libraryDependencies += "org.webjars.npm" % "friendly-errors-webpack-plugin" % "1.7.0"
[org.webjars.npm/friendly-errors-webpack-plugin "1.7.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.webjars.npm : chalk jar [1.1.3,2)
org.webjars.npm : error-stack-parser jar [2.0.0,3)
org.webjars.npm : string-width jar [2.0.0,3)

Project Modules

There are no modules declared in this project.

Friendly-errors-webpack-plugin

npm Build Status Build status

Friendly-errors-webpack-plugin recognizes certain classes of webpack errors and cleans, aggregates and prioritizes them to provide a better Developer Experience.

It is easy to add types of errors so if you would like to see more errors get handled, please open a PR!

Getting started

Installation

npm install friendly-errors-webpack-plugin --save-dev

Basic usage

Simply add FriendlyErrorsWebpackPlugin to the plugin section in your Webpack config.

var FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');

var webpackConfig = {
  // ...
  plugins: [
    new FriendlyErrorsWebpackPlugin(),
  ],
  // ...
}

Turn off errors

You need to turn off all error logging by setting your webpack config quiet option to true.

app.use(require('webpack-dev-middleware')(compiler, {
  // ...
  logLevel: 'silent',
  // ...
}));

If you use the webpack-dev-server, there is a setting in webpack's devServer options:

// webpack config root
{
  // ...
  devServer: {
    // ...
    quiet: true,
    // ...
  },
  // ...
}

If you use webpack-hot-middleware, that is done by setting the log option to false. You can do something sort of like this, depending upon your setup:

app.use(require('webpack-hot-middleware')(compiler, {
  log: false
}));

Thanks to webpack-dashboard for this piece of info.

Demo

Build success

success

eslint-loader errors

lint

babel-loader syntax errors

babel

Module not found

babel

Options

You can pass options to the plugin:

new FriendlyErrorsPlugin({
  compilationSuccessInfo: {
    messages: ['You application is running here http://localhost:3000'],
    notes: ['Some additional notes to be displayed upon successful compilation']
  },
  onErrors: function (severity, errors) {
    // You can listen to errors transformed and prioritized by the plugin
    // severity can be 'error' or 'warning'
  },
  // should the console be cleared between each compilation?
  // default is true
  clearConsole: true,

  // add formatters and transformers (see below)
  additionalFormatters: [],
  additionalTransformers: []
})

Adding desktop notifications

The plugin has no native support for desktop notifications but it is easy to add them thanks to node-notifier for instance.

var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
var notifier = require('node-notifier');
var ICON = path.join(__dirname, 'icon.png');

new FriendlyErrorsPlugin({
    onErrors: (severity, errors) => {
      if (severity !== 'error') {
        return;
      }
      const error = errors[0];
      notifier.notify({
        title: "Webpack error",
        message: severity + ': ' + error.name,
        subtitle: error.file || '',
        icon: ICON
      });
    }
  })

API

Transformers and formatters

Webpack's errors processing, is done in four phases:

  1. Extract relevant info from webpack errors. This is done by the plugin here
  2. Apply transformers to all errors to identify and annotate well know errors and give them a priority
  3. Get only top priority error or top priority warnings if no errors are thrown
  4. Apply formatters to all annotated errors

You can add transformers and formatters. Please see transformErrors, and formatErrors in the source code and take a look a the default transformers and the default formatters.

TODO

  • Make it compatible with node 4

Versions

Version
1.7.0
1.6.1