babel-plugin-minify-guarded-expressions
In
JavaScript
!x && foo();
alert(0 && new Foo());
Out
JavaScript
x || foo();
alert(0);
Installation
- npm
- Yarn
- pnpm
npm install babel-plugin-minify-guarded-expressions --save-dev
yarn add babel-plugin-minify-guarded-expressions --dev
pnpm add babel-plugin-minify-guarded-expressions --save-dev
Usage
With a configuration file (Recommended)
babel.config.json
{
"plugins": ["minify-guarded-expressions"]
}
Via CLI
Shell
babel --plugins minify-guarded-expressions script.js
Via Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["minify-guarded-expressions"]
});