Socket
Socket
Sign inDemoInstall

babel-plugin-feature-flags

Package Overview
Dependencies
0
Maintainers
4
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-feature-flags

A babel transform for managing feature flags


Version published
Weekly downloads
16K
increased by4.61%
Maintainers
4
Install size
9.18 kB
Created
Weekly downloads
 

Changelog

Source

v0.3.1 (2017-03-14)

Full Changelog

Closed issues:

  • An in-range update of babel-core is breaking the build 🚨 #17

Merged pull requests:

Readme

Source

babel-plugin-feature-flags

Build Status

This plugin is for Babel 6. If you need to support Babel 5 use the 0.2.x releases.

A babel plugin that implements feature flags for enabling and disabling features. This plugin is intended to be followed by a dead code elimination pass (Uglify, babel-plugin-dead-code-elimination, etc.) to remove any unreachable code.

Feature flags are implemented by looking for call expressions like isEnabled('my-feature') and checking if the feature is enabled/disabled/disabled in a feature map that is passed through the plugin options. If the feature is known to be enabled or disabled then the call expression is replace with a boolean literal (true or false respectively). If the feature is dynamic, than the call expression is left alone.

Example

Given the .babelrc

{
  "plugins": [["feature-flags", {
    "import": {
        "module": "my-features"
    },
    "features": {
        "new-feature": "disabled"
    }
  }]]
}

the JavaScript file

import isEnabled from 'my-features';

if (isEnabled('new-feature')) {
  // code
}

will be transformed to

import isEnabled from 'my-features';

if (false) {
  // code
}

Configuration

Here are the options that you can pass to the babel plugin.

  • options.import.module [String]: The name of the module that the feature function is imported from.
  • options.import.name [String (Optional)]: The name of the export that the feature function is imported from. Defaults to "default".
  • options.features [Map(String -> 'enabled' | 'disabled' | 'dynamic')]: An object whose keys are the names of features and whose values determine whether the feature is enabled/disabled/dynamic.

Keywords

FAQs

Last updated on 14 Mar 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc