Giter Site home page Giter Site logo

nuxt / friendly-errors-webpack-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from geowarin/friendly-errors-webpack-plugin

26.0 3.0 7.0 779 KB

Recognizes certain classes of webpack errors and cleans, aggregates and prioritizes them to provide a better Developer Experience.

License: MIT License

JavaScript 100.00%

friendly-errors-webpack-plugin's Introduction

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 @nuxt/friendly-errors-webpack-plugin --save-dev

Basic usage

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

var FriendlyErrorsWebpackPlugin = require('@nuxt/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 'warn'
  },
  // should the console be cleared between each compilation?
  // default is true
  clearConsole: true,

  // INFO:    all logs
  // WARNING: warnings and errors
  // ERROR:   only errors
  // SILENT:  no log
  logLevel: true,

  // base: default
  // consola: consola adapter
  // can also be npm package name or reporter object
  reporter: 'consola'

  // 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 NotifierPlugin = require('@nuxt/friendly-errors-webpack-plugin');
var notifier = require('node-notifier');
var ICON = path.join(__dirname, 'icon.png');

new NotifierPlugin({
    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.

Customize Reporters

Reporter is a class for generating output of errors messages, structure is:

  1. Include following levels log methods: success, info, note, warn, error.
  2. Include method clearConsole for clearing the terminal console.

You can take a look at source code as example base reporter

friendly-errors-webpack-plugin's People

Contributors

0xflotus avatar akijoey avatar anasboulmane avatar arjohnston avatar christophehurpeau avatar clarkdo avatar cncolder avatar coreyleelarson avatar danielroe avatar designbyadrian avatar epilande avatar geowarin avatar glavin001 avatar guillermaster avatar haroenv avatar michmich avatar nkzawa avatar ooflorent avatar pi0 avatar pieh avatar pk-nb avatar racer01 avatar rchl avatar richardscarrott avatar sparty02 avatar studiomax avatar sudo-suhas avatar syossan27 avatar timneutkens avatar weaverryan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

friendly-errors-webpack-plugin's Issues

This package relies on vulnerable dependencies

The package currently depends on v2 of string-width, which transitively depend on ansi-regex v3, for which Snyk reports a ReDoS vulnerability.

It would be great to upgrade to the v4 of string-width, which uses a version of ansi-regex that has been patched (upgrading to string-width v5 is harder, as it is an ES module and so might require migrating to ESM too, which would require a major version, which then would still justify upgrading to v4 first to fix things in the existing major version)

Unable to install the latest version

Hi,
I try to install
npm install @nuxt/friendly-errors-webpack-plugin --save-dev or yarn add @nuxt/friendly-errors-webpack-plugin --dev
but prompted me Couldn't find any versions.
image
I found the repository is @nuxtjs/friendly-errors-webpack-plugin
Than I search on npm, You have two packages.
image
And the repository READM.me is the wrong command.
image

Please fix this small problem.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.