rollup-merge-config
raw JSON → 0.0.12 verified Mon Apr 27 auth: no javascript maintenance
Utility to merge multiple Rollup configuration objects with support for custom array and object merging strategies. Current stable version: 0.0.12 (released 2019). Low release cadence (no updates since 2019). Key differentiator: provides array concatenation and object merging specifically tailored for Rollup configs, with optional customizer functions to override default behavior for specific keys. Unlike generic merge libraries (e.g., lodash.merge), it handles Rollup's plugin arrays and nested config structures by default.
Common errors
error Uncaught TypeError: merge is not a function ↓
cause Using default import from CommonJS require where merge is a named export.
fix
Use import { merge } from 'rollup-merge-config' instead of const merge = require('rollup-merge-config').merge
error TypeError: config.push is not a function ↓
cause Misunderstanding that merge can handle arrays of configs like array spread; but merge expects multiple arguments, not an array.
fix
Use merge(config1, config2) or merge(...arrayOfConfigs) with spread, not merge(arrayOfConfigs).
Warnings
gotcha Arrays are concatenated by default, not replaced. This may cause duplicate plugins if the same plugin appears in multiple configs. ↓
fix Use a custom arrayCustomizer to deduplicate, e.g., arrayCustomizer: (a, b, key) => key === 'plugins' ? [...new Set([...a, ...b])] : undefined
gotcha Properties with undefined values are not merged and are skipped. If a config explicitly sets a property to undefined, the previous value remains. ↓
fix Ensure no config sets a property to undefined if you want it removed; use null instead.
gotcha Deep nested objects are merged recursively, but only plain objects. Values like instances of classes or functions are replaced, not merged. ↓
fix If you need to merge non-plain objects, implement a custom objectCustomizer.
deprecated Package has not been updated since 2019; no TypeScript definitions, no Rollup 3+ support. ↓
fix Consider using @rollup/pluginutils mergeOptions or manually merging configs.
Install
npm install rollup-merge-config yarn add rollup-merge-config pnpm add rollup-merge-config Imports
- merge wrong
const merge = require('rollup-merge-config')correctimport { merge } from 'rollup-merge-config' - default wrong
const { merge } = require('rollup-merge-config')correctimport rollupMergeConfig from 'rollup-merge-config' - extend
import { extend } from 'rollup-merge-config'
Quickstart
import { merge } from 'rollup-merge-config';
const baseConfig = {
input: 'src/index.js',
output: { file: 'dist/bundle.js', format: 'cjs' },
plugins: []
};
const clientConfig = {
output: { file: 'dist/client.js', format: 'iife' },
plugins: []
};
const serverConfig = {
output: { file: 'dist/server.js', format: 'cjs' },
plugins: []
};
// Merge multiple configs; later keys override earlier ones.
// Arrays (like plugins) are concatenated.
const merged = merge(baseConfig, clientConfig, serverConfig);
console.log(merged);
// Output: {
// input: 'src/index.js',
// output: { file: 'dist/server.js', format: 'cjs' },
// plugins: []
// }