パッケージの詳細

babel-plugin-feature-flags

ember-cli52.7kMIT0.3.1

A babel transform for managing feature flags

babel, babel-plugin

readme

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.

更新履歴

Change Log

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:

v0.2.3 (2016-09-28)

Full Changelog

Implemented enhancements:

Closed issues:

  • 'broccoli-babel-transpiler is opting out of caching' warning #13

v0.2.2 (2016-08-10)

Full Changelog

Merged pull requests:

v0.3.0 (2016-06-13)

Full Changelog

Implemented enhancements:

  • Babel 6 #5
  • Port plugin to Babel 6 plugin API #6 (Turbo87)

Closed issues:

  • Add a README #1

Merged pull requests:

  • Add README.md #9 (mmun)
  • Add support for multiple instances of the plugin #8 (mmun)
  • Make tests simpler #7 (mmun)

v0.2.1 (2016-06-10)

Closed issues:

  • Better support for unknown feature flags #2

Merged pull requests:

  • Implement a dead code elimination friendly strategy #4 (mmun)
  • Remove + at beginning of every line #3 (pangratz)

* This Change Log was automatically generated by github_changelog_generator