diff --git a/.gitignore b/.gitignore index c2658d7d..a6ec74b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules/ +*.swp diff --git a/lib/build.js b/lib/build.js index af2d2afa..55d7cd2c 100644 --- a/lib/build.js +++ b/lib/build.js @@ -13,6 +13,23 @@ function getBabelTarget(envConfig) { return unknown ? "6.10" : current.replace(/^nodejs/, ""); } + +function loadEnvironment(config) { + var envConfig = config.build.environment || config.build.Environment || {}; + var contextConfig = ( + process.env.CONTEXT && + config.context && + config.context[process.env.CONTEXT] && + (config.context[process.env.CONTEXT].environment || config.context[process.env.CONTEXT].Environment) + ) || {}; + var branchConfig = ( + process.env.BRANCH && + config.context && + config.context[process.env.BRANCH] && + (config.context[process.env.BRANCH].environment || config.context[process.env.BRANCH].Environment) + ) || {}; + return merge(envConfig, contextConfig, branchConfig); +} function haveBabelrc(functionsDir) { const cwd = process.cwd(); @@ -31,7 +48,7 @@ function haveBabelrc(functionsDir) { function webpackConfig(dir, additionalConfig) { var config = conf.load(); - var envConfig = config.build.environment || config.build.Environment || {}; + var envConfig = loadEnvironment(config); var babelOpts = { cacheDirectory: true }; if (!haveBabelrc(dir)) { babelOpts.presets = [