lore
Version:
Convention-driven framework for building React-Redux applications
51 lines (41 loc) • 1.34 kB
JavaScript
import _merge from 'lodash/merge';
import _omit from 'lodash/omit';
/* global __LORE_ROOT__ */
import buildDictionary from 'webpack-requiredir';
// 'config/*'
function loadOtherConfigFiles() {
var context = require.context(__LORE_ROOT__ + '/config', true, /\.js$/);
var config = buildDictionary(context, {
exclude: ['local.js']
});
return _omit(config, 'env');
}
// 'config/local'
function loadLocalOverrideFile() {
var context = require.context(__LORE_ROOT__ + '/config', false, /local.js$/);
var dictionary = buildDictionary(context, {
// options
});
return dictionary.local || {};
}
// 'config/env/*'
function loadEnvConfigFile(env) {
var context = require.context(__LORE_ROOT__ + '/config/env', false, /\.js$/);
var dictionary = buildDictionary(context, {
// options
});
return dictionary[env] || {};
}
export default {
load: function load(env) {
// Load all the config files we need to combine
var configs = {
'config/*': loadOtherConfigFiles(),
'config/local': loadLocalOverrideFile(),
'config/env/*': loadEnvConfigFile(env)
};
// Merge the configs, with env/*.js files taking precedence over others, and local.js
// taking precedence over everything
return _merge(configs['config/*'], configs['config/env/*'], configs['config/local']);
}
};