conradreuter / if-webpack-plugin

Conditionally include Webpack plugins.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

If Webpack Plugin

npm

Installation

npm install --save-dev if-webpack-plugin

or

yarn add -D if-webpack-plugin

Usage

In your Webpack configuration in the plugins section:

// webpack.config.js
const IfPlugin = require('if-webpack-plugin')
const SuperCoolPlugin = require('super-cool-webpack-plugin')
const LessCoolPlugin = require('less-cool-webpack-plugin')
module.exports = {
  // ...
  plugins: [
    new IfPlugin(
      foo === 'bar',
      new SuperCoolPlugin(),
      new LessCoolPlugin()
    )
  ]
}

The third argument can also be omitted in order to include an empty plugin, i.e. a plugin that simply does nothing:

// webpack.config.js
const IfPlugin = require('if-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
module.exports = {
  // ...
  plugins: [
    new IfPlugin(
      process.env.NODE_ENV === 'production',
      new UglifyJsPlugin()
    )
  ]
}

About

Conditionally include Webpack plugins.

License:MIT License


Languages

Language:TypeScript 100.0%