Socket
Socket
Sign inDemoInstall

babel-merge

Package Overview
Dependencies
2
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-merge

[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url]


Version published
Weekly downloads
205K
increased by0.56%
Maintainers
1
Install size
122 kB
Created
Weekly downloads
 

Readme

Source

babel-merge

NPM version NPM downloads

babel-merge takes two Babel configuration objects and merges them into a single copy. Plugin and preset objects and arrays will be merged together.

Requirements

  • Node.js v6.10+
  • Yarn or npm client

Installation

babel-merge can be installed via the Yarn or npm clients.

Yarn
❯ yarn add babel-merge
npm
❯ npm install --save babel-merge

Usage

const merge = require('babel-merge');

const together = merge(
  {
    presets: [
      ['babel-preset-env', {
        targets: {
          browsers: ['latest 1 Chrome']
        }
      }]
    ]
  },
  {
    presets: [
      ['babel-preset-env', {
        targets: {
          browsers: ['latest 1 Firefox']
        }
      }]
    ]
  }
)

console.log(together);

{
  presets: [
    ['babel-preset-env', {
      targets: {
        browsers: [
          'latest 1 Chrome',
          'latest 1 Firefox'
        ]
      }
    }]
  ]
}

If a pathname was used in an earlier merge, you can still merge by exact name:

const merge = require('babel-merge');

const together = merge(
  {
    presets: [
      [require.resolve('babel-preset-env'), {
        targets: {
          browsers: ['latest 1 Chrome']
        }
      }]
    ]
  },
  {
    presets: [
      ['babel-preset-env', {
        targets: {
          browsers: ['latest 1 Firefox']
        }
      }]
    ]
  }
)

console.log(together);

{
  presets: [
    ['/Users/me/code/app/node_modules/babel-preset-env/lib/index.js', {
      targets: {
        browsers: [
          'latest 1 Chrome',
          'latest 1 Firefox'
        ]
      }
    }]
  ]
}

Even works for plugins and presets within environments:

const merge = require('babel-merge');

const together = merge(
  {
    env: {
      development: {
        presets: [
          [require.resolve('babel-preset-env'), {
            targets: {
              browsers: ['latest 1 Chrome']
            }
          }]
        ]
      }
    }
  },
  {
    env: {
      development: {
        presets: [
          ['babel-preset-env', {
            targets: {
              browsers: ['latest 1 Firefox']
            }
          }]
        ]
      }
    }
  }
)

console.log(together);

{
  env: {
    development: {
      presets: [
        ['/Users/me/code/app/node_modules/babel-preset-env/lib/index.js', {
          targets: {
            browsers: [
              'latest 1 Chrome',
              'latest 1 Firefox'
            ]
          }
        }]
      ]
    }
  }
}

Order is preserved between non-option plugins and presets and ones with options:

const merge = require('babel-merge');

const together = merge(
  {
    plugins: [
      'fast-async',
      'babel-plugin-syntax-dynamic-import'
    ]
  },
  {
    plugins: [
      'babel-plugin-transform-object-rest-spread',
      ['fast-async', { spec: true }],
      'babel-plugin-transform-class-properties'
    ]
  }
)

console.log(together);

{
  plugins: [
    ['fast-async', { 'spec': true }],
    'babel-plugin-syntax-dynamic-import',
    'babel-plugin-transform-object-rest-spread',
    'babel-plugin-transform-class-properties'
  ]
}

FAQs

Last updated on 29 Mar 2018

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