<commit_before># 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:**

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

const appConfig = JSON.parse(config);

console.log(appConfig);
```

Console result:

```
{
  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:<commit_msg>Add missing language specifications on code blocks<commit_after># 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:
{'fraction_non_alphanumeric': 0.17498321772208547, 'fraction_numerical': 0.01074065786529425, 'mean_word_length': 1.8489483747609943, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '435588', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1618, 'n_words': 447}