diff --git a/lib/build.js b/lib/build.js index 3c8cf4ef..c94d419f 100644 --- a/lib/build.js +++ b/lib/build.js @@ -5,21 +5,23 @@ var webpack = require("webpack"); var merge = require("webpack-merge"); // custom babel target for each node version -function getBabelTarget(){ +function getBabelTarget(envConfig){ + var key = "AWS_LAMBDA_JS_RUNTIME"; var runtimes = ["nodejs8.10", "nodejs4.3.2", "nodejs6.10.3"]; - var current = process.env["AWS_LAMBDA_JS_RUNTIME"] || "nodejs6.10.3"; + var current = envConfig[key] || process.env[key] || "nodejs6.10.3"; var unknown = runtimes.indexOf(current) === -1; return unknown ? "6.10" : current.replace(/^nodejs/); } function webpackConfig(dir, additionalConfig) { var config = conf.load(); + var envConfig = config.build.environment || config.build.Environment || {}; var babelOpts = {cacheDirectory: true}; if (!fs.existsSync(path.join(process.cwd(), '.babelrc'))) { babelOpts.presets = [ ["env", { targets: { - node: getBabelTarget() + node: getBabelTarget(envConfig) } }] ]; @@ -40,7 +42,6 @@ function webpackConfig(dir, additionalConfig) { // Include environment variables from config if available var defineEnv = {}; - var envConfig = config.build.environment || config.build.Environment || {}; Object.keys(envConfig).forEach((key) => { defineEnv["process.env." + key] = JSON.stringify(envConfig[key]); });