3.0.0 • Published 5 years ago

babel-merge v3.0.0

Weekly downloads
204,700
License
MIT
Repository
github
Last release
5 years ago

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

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'
  ]
}
@citcfe/cicli-plugin-legacy-decoratorsdrg-cli@joseirrazabal/kit@infinitebrahmanuniverse/nolb-babel-m@everything-registry/sub-chunk-1201laravel-mix-version-fixedlaravel-mix-vue-next@alamar/kit@brisk-docs/website@conduitvc/node@conduitvc/react@constgen/neutrino-react-loader@constgen/neutrino-vue-loader@constgen/neutrino-babel-loader@cranejs/plugin-jsx@dword-design/linaria@humblebee/config-babel7@flecks/fleck@flecks/react@flecks/build@leesiongchan/neutrino-middleware-react-css-moduleso2system-blenderneutrino-middleware-compile-loadermixup-plugin-reactmixup-plugin-vuemenreiki2para-scriptsrax-compile-configreact-scripts-ws-webextensionreduktremote-modulesrocketact-plugin-legacy-decoratorsrocketact-plugin-react-refreshrocketact-plugin-yep-reactrocketact-scriptsrhino-clitapestry-liteteeheetampjssuperkaolatenon-apptossjsumi-plugin-libraryumi-plugin-library-testtreatswebpack-mixwebext-react-scriptsxeiraxin-mixpackvenus-scriptsyh-mix@alifd/build-plugin-meet-component@alifd/build-plugin-meet-docs@kotify/neutrino-react-refresh@kotify/neutrino-typescript@linaria/utils@lunde/build-react-app@lunde/configure-react-app@rispa/babel@reactml/loader@reggi/lerna.utils@sanity-codegen/groq-codegen@sanity-codegen/schema-codegen@sanity-codegen/cli@sanity-codegen/core@sanity-codegen/extractor@pajn-linaria/utils@pixpa/laravel-mix@plateui/config-babel7@neutrinojs/karma@neutrinojs/library@neutrinojs/mocha@neutrinojs/node@neutrinojs/preact@neutrinojs/react@neutrinojs/web@nextj/kit@stellar-apps/webpackbuild-plugin-utilsbuild-scripts-config-rax@vtex/micro-assets@vtex/micro-core@vtex/micro-css@vtex/micro-plugin-assets@vtex/micro-plugin-css@vtex/micro-plugin-react@vtex/micro-plugin-react-intl@vtex/micro-plugin-react-router@vtex/micro-react@vtex/micro-react-intl@vtex/micro-react-router@winme/webpack-scripts@wyw-in-js/transform@toruslabs/torus-scriptsbatpackbuild-plugin-component-multiplebuild-plugin-rax-halo-componentcicli-plugin-legacy-decoratorscjetcjet-beta
3.0.0

5 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.1

6 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago