# config-merge-loader

> Loader for mergeing environment specific localiztion or configuration into a base set at build time.

Latest version **1.0.0-beta.6** (published 2017-07-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install config-merge-loader
pnpm add config-merge-loader
yarn add config-merge-loader
bun add config-merge-loader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-beta.6 |
| Published | 2017-07-18 |
| First published | 2017-07-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 <9.0.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Alex Lemanski |
| Maintainers | bitfyre |
| Keywords | webpack, loader, config, locale, merge, yaml, yml, json |

## Links

- npm: https://www.npmjs.com/package/config-merge-loader
- Repository: https://github.com/bitfyre/config-merge-loader
- Homepage: https://github.com/bitfyre/config-merge-loader/issues
- Issues: https://github.com/bitfyre/config-merge-loader/issues
- npm.io page: https://npm.io/package/config-merge-loader

## Dependencies (1)

- [loader-utils](https://npm.io/package/loader-utils.md) ^1.1.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.0-beta.6 (latest) — 2017-07-18
- 1.0.0-beta.5 — 2017-07-12
- 1.0.0-beta.4 — 2017-07-11
- 1.0.0-beta.3 — 2017-07-11
- 1.0.0-beta.2 — 2017-07-10
- 1.0.0-beta.1 — 2017-07-08

## README

# config-merge-loader for Webpack

A webpack loader for merging configuration or localization files with a base set at build time. It should work with most loaders that generate JSON.

## Installation

`npm install config-merge-loader --save`

## Usage

This is intended to be used with loaders that poduce a JSON out put, like the json-loader itself or the yaml-loader.

### Basic Usage

**base.json:**

```json
{
  "a": 1,
  "b": {
    "a": 1,
    "b": 1
  },
  "c": 1
}
```

**override.json:**

```json
{
  "a": 2,
  "b": {
    "a": 2
  }
}
```

**webpack.config.js:**

```javascript
{
  …
  module: {
   rules: [
     {
       test: /\.json$/, use: 'json-loader'
     },
     {
       test: /base\.json$/,
       use: [
         {
           loader: 'config-merge-loader',
           query: {
             override: 'override.json'
           }
         }
       ]
      }
    ]
  }
  …
}

```

Then in your application code you can do the following

**entry.js:**

```javascript
import config from './base.json'

const appConfig = JSON.parse(config);

console.log(appConfig);

```

Console result:

```javascript
{
  a: 2,
  b: {
    a: 2,
    b: 1
  },
  c: 1
}
```

### Usage With `yaml-loader`

**base.yml:**

```yaml
a: 1
b:
  a: 1
  b: 1
c: 1
```

**override.yml:**

```yaml
a: 2
b:
  a: 2
```

**webpack.config.js:**

```javascript
{
  …
  module: {
    rules: [
      {
        test: /\.yml$/, use: [
          { loader: 'json-loader' },
          { loader: 'yaml-loader' }
        ]
      },
      {
        test: /base\.yml$/,
        use: [
          {
            loader: 'config-merge-loader',
            query: {
              override: 'override.yml'
            }
          },
          { loader: 'yaml-loader' }
        ]
      }
    ]
  }
  …
}
```

Then in your application code you can do the following

**entry.js:**

```javascript
import config from './base.yml'

const appConfig = JSON.parse(config);

console.log(appConfig);
```

Console result:

```javascript
{
  a: 2,
  b: {
    a: 2,
    b: 1
  },
  c: 1
}
```

### Usage When Merging Different Namespaces

**base.yml:**

```yaml
locale:
  a: 1
  b:
    a: 1
    b: 1
  c: 1
```

**override.yml:**

```yaml
override:
  a: 2
  b:
    a: 2
```

**webpack.config.js:**

```javascript
{
  …
  module: {
    rules: [
      {
        test: /\.yml$/, use: [
          { loader: 'json-loader' },
          { loader: 'yaml-loader' }
        ]
      },
      {
        test: /base\-namespace\.yml$/,
        use: [
          {
            loader: 'config-merge-loader',
            query: {
              baseNamespace: 'locale',
              override: 'override-namespace.yml',
              overrideNamespace: 'override'
            }
          },
          { loader: 'yaml-loader' }
        ]
      }
    ]
  }
  …
}
```

Then in your application code you can do the following

**entry.js:**

```javascript
import locale from './base-namespace.yml'

const appLocale = JSON.parse(locale);

console.log(appLocale);
```

Console result:

```javascript
{
  locale: {
    a: 2,
    b: {
      a: 2,
      b: 1
    },
    c: 1
  }
}
```

## Options

`override` (required) string: Path to the override file. This will be merged in into the base file that is defined via an `import` or `require` statement.

`baseNamespace` (optional) string: the name of the key for the base object. This results in this name being kept in the output, and only it properties inside of it being updated.

`overrideNamespace` (optional) string: the name of top level key in the override object that will be used to override the base object.

**Note:** Currently `baseNamespace` and `overrideNamespace` can only select one level deep.

---
_Source: https://npm.io/package/config-merge-loader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
