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
- Host: GitHub
- URL: https://github.com/karolis-sh/rollup-plugin-json-merge
- Owner: karolis-sh
- License: mit
- Created: 2021-06-13T20:40:42.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-07-08T20:52:06.000Z (almost 5 years ago)
- Last Synced: 2025-03-21T08:46:11.342Z (over 1 year ago)
- Topics: json, merge, rollup, rollup-plugin
- Language: JavaScript
- Homepage:
- Size: 139 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# rollup-plugin-json-merge
[![npm version][package-version-badge]][package-version]
[](https://github.com/karolis-sh/rollup-plugin-json-merge/actions/workflows/node.js.yml)
[](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