From 1008ebc24b5fcf10c6dc1f4d33aafcd21a318603 Mon Sep 17 00:00:00 2001 From: Leonardo Dino Date: Wed, 4 Apr 2018 09:56:55 -0300 Subject: [PATCH 1/2] custom babel target for each node version --- lib/build.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/build.js b/lib/build.js index 094b22f5..3c8cf4ef 100644 --- a/lib/build.js +++ b/lib/build.js @@ -4,6 +4,14 @@ var conf = require("./config"); var webpack = require("webpack"); var merge = require("webpack-merge"); +// custom babel target for each node version +function getBabelTarget(){ + var runtimes = ["nodejs8.10", "nodejs4.3.2", "nodejs6.10.3"]; + var current = process.env["AWS_LAMBDA_JS_RUNTIME"] || "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 babelOpts = {cacheDirectory: true}; @@ -11,7 +19,7 @@ function webpackConfig(dir, additionalConfig) { babelOpts.presets = [ ["env", { targets: { - node: "6.10" + node: getBabelTarget() } }] ]; From aa9e82c42694a503dbf3e2b577510e503fbaddc1 Mon Sep 17 00:00:00 2001 From: Leonardo Dino Date: Wed, 4 Apr 2018 10:05:59 -0300 Subject: [PATCH 2/2] read runtime from netlify.toml --- lib/build.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/build.js b/lib/build.js index 3c8cf4ef..6a5b6cf3 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/); + 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]); });