An open API service indexing awesome lists of open source software.

https://github.com/karolis-sh/rollup-plugin-json-merge

A Rollup plugin to merge multiple JSON sources into one
https://github.com/karolis-sh/rollup-plugin-json-merge

json merge rollup rollup-plugin

Last synced: 2 months ago
JSON representation

A Rollup plugin to merge multiple JSON sources into one

Awesome Lists containing this project

README

          

# rollup-plugin-json-merge

[![npm version][package-version-badge]][package-version]
[![Node.js CI](https://github.com/karolis-sh/rollup-plugin-json-merge/actions/workflows/node.js.yml/badge.svg)](https://github.com/karolis-sh/rollup-plugin-json-merge/actions/workflows/node.js.yml)
[![License: MIT](https://img.shields.io/badge/license-mit-yellow.svg)](https://opensource.org/licenses/MIT)

🍣 A Rollup plugin to merge multiple JSON sources into one.

## Install

Using npm:

```console
npm i rollup-plugin-json-merge --save-dev
```

Using yarn:

```console
yarn add rollup-plugin-json-merge -D
```

## Usage

Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files)
and import the plugin:

```js
import merge from 'rollup-plugin-json-merge';
import { name, version, description } from './package.json';

export default {
input: 'src/index.js',
output: {
dir: 'output',
format: 'cjs',
},
plugins: [
merge({
input: [{ name, version, description }, 'src/manifest.json', 'src/data/*.json'],
fileName: 'manifest.json',
}),
],
};
```

Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference)
or the [API](https://www.rollupjs.org/guide/en/#javascript-api).

The configuration above will collect JSON values from given input option and
build the output file using `Object.assign`.

## Options

### `input`

Type: `(String | JSONValue)` | `Array[...(String | JSONValue)]`

Default: `[]`

[Glob](https://www.npmjs.com/package/glob) style string pattern or a JSON object
or an array of a mix of those to construct a single output from.

### `fileName`

Type: `String`

Default: `output.json`

Output filename for the merged JSON.

### `merge`

Type: `Function`

Default: `(items) => Object.assign(...items)`

The function responsible for merging given items.

## License

[MIT](/LICENSE)

[package-version-badge]: https://badge.fury.io/js/rollup-plugin-json-merge.svg
[package-version]: https://www.npmjs.com/package/rollup-plugin-json-merge