Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-conditional

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-conditional

Conditionally applies a set of babel plugins based on the result of an expression evaluated at runtime.

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
26
increased by8.33%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-conditional

Conditionally applies a set of babel plugins based on the result of an expression evaluated at runtime.

What?

Yes, an explanation would be nice. See https://github.com/codemix/flow-runtime/issues/64 for some background for what and why.

Installation

yarn add --dev babel-plugin-conditional

Add the following to your .babelrc or babel configuration:

{
  "plugins": [
    ["conditional", {
      "test": "process.env.NODE_ENV === 'development'",
      "consequent": [["some-plugin-you-want-to-run-only-in-dev"]],
      "alternate": [["some-plugin-you-want-to-run-only-in-prod"]]
    }]
  ]
}

Now given an input like this:

export const add = (a, b) => a + b;

it will produce output like this:

export let add;
if (process.env.NODE_ENV === 'development') {
  const _add = (a, b) => {
    return a + b;
  };
  add = _add;
}
else {
  const _add = (a, b) => a + b;
  add = _add;
}

The condition can then be stripped by tools such as webpack or rollup, so you only get one of the branches in production, but library authors can ship a one set of file that covers both debug and production use cases.

Licence

MIT.

Licence

FAQs

Package last updated on 05 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc