Search code examples
javascriptember.jsember-cli

Deep merging configs of host app and addon in ember


Normally config/environment.js files of host application and addon are merged. But top level only.

For example:

//addon config/environment.js    
module.exports = function() {
    return {
        addonRootVar: 'exist after merge'
        APP: {
            addonDeepVar: 'doesn\'t exist in resulting config'
        }     
    }
}

//host app config/environment.js
module.exports = function() {
return {
    hostRootVar: 'exist after merge'
        APP: {
            hostDeepVar: 'whole APP property will be overwritten :('
        }
    }
}

Is it possible to deepMerge configs?(to have both addonDeepVar and hostDeepVar present in resulting config) If yes – How?


Solution

  • I've made a mistake. Actually configs are merged(deep) by default. But the config is generated once per ember-cli server start(no recreation when file changes). So every time you modify any of the configs, you have to relaunch server in order to avoid the unpredictability.