tettusud / merge-jsons-webpack-plugin

This plugin is used to merge json files into single json file,using glob or file names
https://npmjs.com/package/merge-jsons-webpack-plugin
Apache License 2.0
36 stars 20 forks source link

Previous content overwritten instead of added to #56

Closed ssuess closed 4 years ago

ssuess commented 4 years ago

I have a pattern of language specific folders (/src/i18n/en,/src/i18n/es, etc) that I am matching to find files under each and merge them, but using the following code, the output file only contains the last language. I realize this is probably because inside each language file the structures are the same, ie:

{ "helloMsg": "hello" } and { "helloMsg": "hola" }

instead of

{ "en": { "helloMsg": "hello"} } and { "es": { "helloMsg": "hola"} }

Is there a way for this plugin to write the pattern name of the folder into each grouping before writing it to the file? My translation software unfortunately seems to need me to keep the pattern above for it to be able to write those files to the folders properly.

Below is what my current code looks like

new MergeJsonWebpackPlugin({
            "debug": true,
            "output": {
              "groupBy": [
                  {
                      "pattern": "./src/i18n/*/item-specific/ThisItem.json",
                      "fileName": "./src/i18n/compiled/ThisItem.json"
                  },
                  {
                      "pattern": "./src/i18n/*/item-specific/ThatItem.json",
                      "fileName": "./src/i18n/compiled/ThatItem.json"
                  },
              ]
            },
            "globOptions": {
                "nosort": true
            }
          })
tettusud commented 4 years ago

There is an option prefix file name did you try that ?

ssuess commented 4 years ago

This isn't a file naming problem. It is a file content problem. But in any event, I just wrote my own script to take care of the merging I need. Thanks anyway.