Giter Site home page Giter Site logo

0-admin / babel-merge Goto Github PK

View Code? Open in Web Editor NEW

This project forked from neutrinojs/babel-merge

0.0 2.0 0.0 206 KB

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

License: MIT License

JavaScript 100.00%

babel-merge's Introduction

babel-merge

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

NPM version NPM downloads

Note: options to plugins and presets will not be merged, but instead replaced by the last matching item's options. This makes the behavior consistent with how Babel works.

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

  • merge(a, b, options)
  • merge.all([a, b, ..., z], options)

Where a, b, z are Babel configuration objects and options is a deepmerge options object.

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 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 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 Firefox'
            ]
          }
        }]
      ]
    }
  }
}

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

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

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

console.log(together);

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

babel-merge's People

Contributors

eliperelman avatar renovate-bot avatar renovate[bot] avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.