Socket
Socket
Sign inDemoInstall

@armit/babel-merge

Package Overview
Dependencies
2
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @armit/babel-merge

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


Version published
Maintainers
1
Created

Readme

Source

@armit/babel-merge

@armit/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 v18+
  • Yarn or npm client

Installation

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

Yarn
❯ yarn add @armit/babel-merge
npm
❯ npm install --save @armit/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.

import { babelMerge } from "@armit/babel-merge";

const together = babelMerge(
  {
    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:

import { babelMerge } from "@armit/babel-merge";

const together = babelMerge(
  {
    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:

import { babelMerge } from "@armit/babel-merge";

const together = babelMerge(
  {
    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:

import { babelMerge } from "@armit/babel-merge";

const together = babelMerge(
  {
    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",
  ];
}

FAQs

Last updated on 13 May 2024

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