Skip to content

Commit

Permalink
Merge pull request #25 from leonardodino/custom-runtime
Browse files Browse the repository at this point in the history
Custom Babel env target
  • Loading branch information
biilmann authored Apr 15, 2018
2 parents d1e47ab + aa9e82c commit 5ea3ec5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@ var conf = require("./config");
var webpack = require("webpack");
var merge = require("webpack-merge");

// custom babel target for each node version
function getBabelTarget(envConfig){
var key = "AWS_LAMBDA_JS_RUNTIME";
var runtimes = ["nodejs8.10", "nodejs4.3.2", "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: "6.10"
node: getBabelTarget(envConfig)
}
}]
];
Expand All @@ -32,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 5ea3ec5

Please sign in to comment.