ember.jsbuildember-cliember-addon

Combine Addon Vendor Files During Ember CLI Build


Say I have three custom Ember addons...

addon-a
addon-b
addon-c

I want each addon to contain its own vendor/translations/ folder containing different JSON files for each locale.

addon-a
  vendor
    translations
      en.json
      es.json
      ...
addon-b
  vendor
    translations
      en.json
      es.json
      ...
addon-c
  vendor
    translations
      en.json
      es.json
      ...

I want to include these three addons in my main Ember.js application (my-app). During the build process I want to create one JSON file per locale, containing the contents of all three addons.

// my-app's final en.json file.
{
    "addon-a": {
        // addon-a en.json contents output here.
    },
    "addon-b": {
        // addon-b en.json contents output here.
    },
    "addon-c": {
        // addon-c en.json contents output here.
    }
}

I am using app.import('vendor/translations/en.json') to include the addon's JSON files into my-app's build output. However, I am stuck on trying to create the single JSON files for each locale. I then want to remove the addon's JSON files that were imported to create the concatenated files.

Is what I am trying to do possible? If so, can anyone provide steps on how to achieve this or point me to an example of something similar? Thanks!


Solution

  • After some thought, I believe the best way to do this is through the creation of a custom Broccoli Plugin within the Ember application. The plugin would iterate through all addons and aggregate all the translations into joint files at build time.

    This answer is based off of ember-intl's TranslationReducer Broccoli plugin.