Skip to content

Latest commit

 

History

History
88 lines (64 loc) · 2.06 KB

README.md

File metadata and controls

88 lines (64 loc) · 2.06 KB

esbuild-plugin-json-merge

npm version Node.js CI License: MIT

Merging multiple JSON sources into one via esbuild pipeline.

Installation

npm i esbuild-plugin-json-merge -D

or

yarn add esbuild-plugin-json-merge --dev

Usage

const esbuild = require('esbuild');
const jsonMerge = require('esbuild-plugin-json-merge');

const { version, name, description } = require('./package.json');

esbuild
  .build({
    entryPoints: ['src/index.js'],
    outdir: 'build',
    plugins: [
      jsonMerge({
        entryPoints: ['src/manifest.json', { version, name, description }],
        outfile: 'manifest.json',
      }),
    ],
  })
  .catch(() => process.exit(1));

Options

entryPoints

Type: (string | object)[]

An array of glob patterns or JSON objects that should be merged.

outfile

Type: string

JSON output destination.

merge

Type: (items: JSONValue[]) => JSONValue

By default the merge function uses Object.assign.

const esbuild = require('esbuild');
const jsonMerge = require('esbuild-plugin-json-merge');
const { defaultComposer } = require('default-composer');

const { version, name, description } = require('./package.json');

esbuild
  .build({
    entryPoints: ['src/index.js'],
    outdir: 'build',
    plugins: [
      jsonMerge({
        entryPoints: ['src/manifest.json', { version, name, description }],
        outfile: 'manifest.json',
        merge: (items) => defaultComposer(...items), //Custom merge
      }),
    ],
  })
  .catch(() => process.exit(1));