项目作者: developit

项目描述 :
:dizzy: Create a modified babel preset based on an an existing preset.
高级语言: JavaScript
项目地址: git://github.com/developit/modify-babel-preset.git
创建时间: 2016-01-10T03:22:30Z
项目社区:https://github.com/developit/modify-babel-preset

开源协议:

下载


modify-babel-preset

npm
npm
travis

Create a modified babel preset based on an an existing preset.

Works best with npm 3.

  1. npm i -S modify-babel-preset


API

A single function that takes an existing preset name and a mapping of plugin modifications to apply to that preset. Make sure you have the preset and any added plugins installed as dependencies.

  1. newPreset = modifyBabelPreset(
  2. 'existing-preset-name',
  3. {
  4. 'plugin-name': false, // remove
  5. 'other-plugin': true, // add
  6. 'foo': { loose:true } // add + config
  7. }
  8. );

Modification keys are babel plugin names (you can exclude the babel-plugin- prefix).

Add/Update Plugins

To add a plugin, pass true, or a configuration object:

  1. {
  2. // just add a plugin without config:
  3. 'plugin-name': true,
  4. // add a plugin and set its config
  5. 'other-plugin': { loose:true }
  6. }

Note: adding a plugin that is already provided by the preset just overwrites its configuration.

Remove Plugins

To remove a plugin, pass false:

  1. {
  2. 'plugin-name': false
  3. }

Example

Here’s a simple preset. Just this index.js and a package.json pointing to it with the preset and plugin installed as dependencies.

  1. var modifyBabelPreset = require('modify-babel-preset');
  2. // just export the cloned, modified preset config:
  3. module.exports = modifyBabelPreset('es2015', {
  4. // remove the typeof x==='symbol' transform:
  5. 'transform-es2015-typeof-symbol': false,
  6. // add the JSX transform:
  7. 'transform-react-jsx': true
  8. });