Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Babel env target #25

Merged
merged 2 commits into from
Apr 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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