Skip to content

Commit

Permalink
read runtime from netlify.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardodino committed Apr 13, 2018
1 parent 1008ebc commit d4e0f5c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}]
];
Expand All @@ -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]);
});
Expand Down

0 comments on commit d4e0f5c

Please sign in to comment.