conditional-webpack-plugin

1.0.5 • Public • Published

Conditional-Webpack-Plugin

A webpack plugin that could exclude the compiled content conditionally. That's very useful if you intent to compile you project with some different modules by run specify npm script. Note that this plugin is valid for fowllowing types of file: html[not template of Html-Webpack-Plugin], js, ts, jsx, tsx, vue, css, scss, sass, less


install

npm install conditional-webpack-plugin -D
yarn add conditional-webpack-plugin -D

Usage

// webpack.config.js

const ConditionalWebpackPlugin = require("conditional-webpack-plugin")

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

There are two ways to exclude the content you don't want: if true: statement and if def: variable, and both of them need to use endif to mark the end:

console.log("I will be shown")

// if true: true && 10 < 1
console.log("I will not be shown")
// endif

// if def: VARIABLE_NOT_EXIST
consle.log("I will not be shown either")
// endif

No matter which way you will pick, the process.env will be added at the beginning of the scope. That is to say, VARIABLE will be attempted to be interpreted as process.env.VARIABLE.

Also, you maybe have noticed that if def: VARIABLE is the abbreviation form of if true: VARIABLE !== undefined

Package Sidebar

Install

npm i conditional-webpack-plugin

Weekly Downloads

1

Version

1.0.5

License

MIT

Unpacked Size

25.6 kB

Total Files

10

Last publish

Collaborators

  • mlgq