concat-merge
Version:
Recursively merge objects
46 lines (33 loc) • 2.53 kB
Markdown
# concat-merge
[](https://github.com/ambar/concat-merge/actions/workflows/test.yml)
Recursively merge objects, especially for webpack/rollup configs.
## Comparison
| name | immutable | concat | dedupe | clone | multiple parameters | recommended |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ---------------- | ---------------- | ---------------- | ------------------- | ----------- |
| concat-merge <br> [](https://bundlephobia.com/package/concat-merge) | `true` | `true` | `false` | `true` | no | yes |
| merge-deep <br> [](https://bundlephobia.com/package/merge-deep) | `true` | `true` | `true` | `true` | yes | yes |
| deepmerge <br> [](https://bundlephobia.com/package/deepmerge) | `true` | `true` | `false` | `false` (option) | no | |
| lodash/merge <br> [](https://bundlephobia.com/package/lodash.merge) | `false` | `false` | `false` | `true` | yes | |
| lodash/mergeWith <br> [](https://bundlephobia.com/package/lodash.mergewith) | `false` | `false` (option) | `false` (option) | `true` | yes | yes |
## Install
```
npm install concat-merge
```
## Usage
```js
import concatMerge from 'concat-merge'
concatMerge(baseConfig, {
input: 'entry.js',
plugins: [inject({React: 'react'})],
})
```
lodash equivalent:
```js
import mergeWith from 'lodash/mergeWith'
const concatMerge = (...args) =>
mergeWith({}, ...args, (prev, next) => {
if (Array.isArray(prev)) {
return prev.concat(next)
}
})
```