y-conditional-webpack-plugin
v1.0.9
Published
A Webpack loader that can ignore compilation content through conditions.
Downloads
8
Maintainers
Readme
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 y-conditional-webpack-plugin -Dyarn add y-conditional-webpack-plugin -Dpnpm i -D y-conditional-webpack-pluginUsage
// 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: env.VARIABLE_NOT_EXIST
consle.log("I will not be shown either")
// endifNo 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: env.VARIABLE is the abbreviation form of if true: env.VARIABLE !== undefined
