rollup-plugin-json-merge

raw JSON →
0.0.2 verified Mon Apr 27 auth: no javascript

A Rollup plugin (v0.0.2, stable but minimal) that merges multiple JSON sources into one output file during bundle build. Supports glob patterns, inline objects, and custom merge functions. Lightweight alternative to manual JSON combination in Rollup pipelines. No major updates since initial release; less feature-rich than @rollup/plugin-json combined with manual merging but simpler for single-file concatenation.

error Error: Cannot find module 'glob'
cause Missing glob peer dependency.
fix
npm install glob --save-dev
error TypeError: merge is not a function
cause Using named import incorrectly.
fix
Use default import: import merge from 'rollup-plugin-json-merge'
error Error: Could not resolve 'rollup-plugin-json-merge'
cause Package not installed.
fix
npm install rollup-plugin-json-merge --save-dev
gotcha Plugin may not handle conflicting keys across input files; uses shallow assign by default.
fix Provide custom merge function via options.merge to handle conflicts (e.g., deep merge).
gotcha Glob patterns in input must resolve to absolute paths or relative to process.cwd(); no automatic resolution.
fix Use path.resolve or ensure patterns are correct relative to working directory.
gotcha Plugin does not emit warnings for non-existent files; silent failure if no files matched.
fix Validate input files exist before configuring plugin.
npm install rollup-plugin-json-merge
yarn add rollup-plugin-json-merge
pnpm add rollup-plugin-json-merge

Minimal Rollup config that merges two JSON files into one output using the plugin.

import merge from 'rollup-plugin-json-merge';
export default {
  input: 'src/index.js',
  output: { dir: 'output', format: 'cjs' },
  plugins: [
    merge({
      input: ['src/part1.json', 'src/part2.json'],
      fileName: 'combined.json',
    }),
  ],
};