Giter VIP home page Giter VIP logo

warnings-to-errors-webpack-plugin's Introduction

Warnings To Errors Webpack Plugin Build Status

Table of contents

Motivation

Even if the build result with webpack has some warnings, the build can succeed with no error exit codes. This can be trouble if some developer not carefully sees the result of CI service. By changing all warnings to errors, webpack can recognize every warning as an error.

Installation

$ npm i -D warnings-to-errors-webpack-plugin
# or
$ yarn add -D warnings-to-errors-webpack-plugin

Usage

  • default
const WarningsToErrorsPlugin = require('warnings-to-errors-webpack-plugin');

module.exports = {
  // ...
  plugins: [
    new WarningsToErrorsPlugin(),
  ],
};

This plugin ignores warnings that are matched by warningsFilter or ignoreWarnings without recognizing them as errors.

// webpack v5
{
  plugins: [
    new WarningsToErrorsPlugin(),
  ],
  ignoreWarnings: [
    {
      message: /compilation warning/,
    },
  ],
}

If you use ignoreWarnings and warningsFilter options at the same time in webpack v5, the plugin will ignore all matched warnings in both. but recommend using ignoreWarnings only.

// webpack v5
{
  plugins: [
    new WarningsToErrorsPlugin(),
  ],
  ignoreWarnings: [
    {
      message: /compilation warning 1/,
    },
  ],
  stats: {
    warningsFilter: [
      /compilation warning 2/,
    ],
  },
}
// webpack v2, v3 and v4
{
  plugins: [
    new WarningsToErrorsPlugin(),
  ],
  stats: {
    warningsFilter: [
      /compilation warning/,
    ],
  },
}

Skip the emitting phase whenever there are warnings while compiling. this ensures that no assets are emitted that include warnings.

// webpack >= v4
{
  optimization: {
    noEmitOnErrors: true,
  },
  plugins: [
    new WarningsToErrorsPlugin();
  ],
};
// webpack v2 and v3
{
  plugins: [
    new WarningsToErrorsPlugin(),
    new NoEmitOnErrorsPlugin(),
  ],
};

License

MIT © Taehwan Noh

warnings-to-errors-webpack-plugin's People

Contributors

alessioprestileo avatar bes avatar dependabot[bot] avatar taehwanno avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

warnings-to-errors-webpack-plugin's Issues

TypeScript typings

Nice plugin! I am using a webpack-config.ts (TypeScript for Webpack).

Would it be possible to add TypeScript types to this project?

If possible, I would prefer if the types are added to the repo directly and not to the @types/-project.

Do you take contributions? In that case I might be able to do it.

`warningsFilter` does not behave in the same manner as the default Webpack option

Followup to: 07bcf47

This works if were targeting the warning message, but NOT the module id or context that triggered the warning.

Example Warning Object:

{
  message: 'Critical dependency: the request of a dependency is an expression',
  module: {
    context: '/local-path/node_modules/yargs',
	id: './node_modules/yargs/index.cjs',
  },
}
// Does NOT work
webpackOptions.stats.warningsFilter: [/node_modules\/yargs/i];

// Works
webpackOptions.stats.warningsFilter: ['the request of a dependency is an expression'];

Note: If this plugin is not used, the [/node_modules\/yargs/i] warning filter works fine -- they are just not transitioned to errors.

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.