merge-jsons-webpack-plugin icon indicating copy to clipboard operation
merge-jsons-webpack-plugin copied to clipboard

Deep merge with file path

Open loginov-rocks opened this issue 5 years ago • 3 comments

Hello!

Is it possible to do like so:

Your application structure:

/src/app/
|-- catalog
|   |-- catalogItem
|   |   |-- locales
|   |   |   |-- en.json
|   |   |   `-- ru.json
|   |   `-- catalogItem.component.js
|   |-- locales
|   |   |-- en.json
|   |   `-- ru.json
|   `-- catalog.component.js
`-- user
    |-- locales
    |   |-- de.json 
    |   |-- en.json
    |   `-- ru.json
    `-- user.component.js

After using the above gulpfile.js:

/dist/locales/
|-- de.json
|-- en.json
`-- ru.json

The en.json file will look like this:

{
  "catalog": {
    "catalogItem": {
      // contents of `/src/app/catalog/catalogItem/locales/en.json`
    },
    // contents of `/src/app/catalog/locales/en.json`
  },
  "user": {
    // contents of `/src/app/user/locales/en.json`
  }
}

So you can obtain values using dot notation, catalog.catalogItem.headline for example.

Gulp example: https://github.com/loginov-rocks/gulp-locales-bundler/blob/master/src/gulpLocalesBundler.js

loginov-rocks avatar Mar 04 '19 18:03 loginov-rocks

Made a straightforward function FYI: https://github.com/loginov-rocks/locales-bundler/blob/master/src/localesBundler.js#L15-L42

loginov-rocks avatar Mar 11 '19 02:03 loginov-rocks

@loginov-rocks apologies, I was little away from this repo, I will check this .By the way thanks for dropping the suggestion

tettusud avatar Apr 04 '19 07:04 tettusud

@loginov-rocks , a new package 0.0.19 was published, is that something that could help you?

tettusud avatar Apr 28 '19 23:04 tettusud