https://github.com/karolis-sh/esbuild-plugin-json-merge
Merging multiple JSON sources into one via esbuild pipeline
https://github.com/karolis-sh/esbuild-plugin-json-merge
esbuild esbuild-plugin json merge
Last synced: 12 months ago
JSON representation
Merging multiple JSON sources into one via esbuild pipeline
- Host: GitHub
- URL: https://github.com/karolis-sh/esbuild-plugin-json-merge
- Owner: karolis-sh
- License: mit
- Created: 2021-07-15T06:52:16.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-12-08T22:55:04.000Z (over 2 years ago)
- Last Synced: 2025-05-26T00:52:41.967Z (about 1 year ago)
- Topics: esbuild, esbuild-plugin, json, merge
- Language: TypeScript
- Homepage:
- Size: 1.49 MB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# esbuild-plugin-json-merge
[![npm version][package-version-badge]][package-version]
[](https://github.com/karolis-sh/esbuild-plugin-json-merge/actions/workflows/node.js.yml)
[](https://opensource.org/licenses/MIT)
Merging multiple JSON sources into one via [esbuild](https://esbuild.github.io/)
pipeline.
## Installation
```bash
npm i esbuild-plugin-json-merge -D
```
or
```bash
yarn add esbuild-plugin-json-merge --dev
```
## Usage
```js
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](https://www.npmjs.com/package/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`.
```js
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));
```
[package-version-badge]: https://badge.fury.io/js/esbuild-plugin-json-merge.svg
[package-version]: https://www.npmjs.com/package/esbuild-plugin-json-merge