简体   繁体   English

在Ember CLI构建期间合并插件供应商文件

[英]Combine Addon Vendor Files During Ember CLI Build

Say I have three custom Ember addons... 假设我有三个自定义的Ember插件...

addon-a
addon-b
addon-c

I want each addon to contain its own vendor/translations/ folder containing different JSON files for each locale. 我希望每个插件都包含其自己的vendor / translations /文件夹,其中包含针对每个区域设置的不同JSON文件。

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 ). 我想在我的主要Ember.js应用程序( my-app )中包括这三个插件。 During the build process I want to create one JSON file per locale, containing the contents of all three addons. 在构建过程中,我想为每个语言环境创建一个JSON文件,其中包含所有三个插件的内容。

// 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. 我正在使用app.import( 'vendor / translations / en.json'将插件的JSON文件包含到my-app的生成输出中。 However, I am stuck on trying to create the single JSON files for each locale. 但是,我坚持尝试为每个语言环境创建单个JSON文件。 I then want to remove the addon's JSON files that were imported to create the concatenated files. 然后,我想删除导入来创建级联文件的插件的JSON文件。

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! 谢谢!

After some thought, I believe the best way to do this is through the creation of a custom Broccoli Plugin within the Ember application. 经过一番思考,我相信最好的方法是通过在Ember应用程序中创建自定义的Broccoli插件。 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 . 该答案基于ember-intl的TranslationReducer Broccoli插件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM