From 9117c36d858d228130b8a6c11db2eead33107f53 Mon Sep 17 00:00:00 2001 From: Ollie Monk Date: Fri, 17 May 2019 13:30:59 +0800 Subject: [PATCH] add new flag to opt out of default babelrc loading --- .gitignore | 1 + bin/cmd.js | 13 ++++++++++++- lib/build.js | 8 ++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index a6ec74b1..7bfa5e6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ +.vscode/ *.swp diff --git a/bin/cmd.js b/bin/cmd.js index 16f637fd..5518c6af 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -15,9 +15,18 @@ var serve = require("../lib/serve"); program.version(pkg.version); +const stringBooleanToBoolean = val => { + if (typeof val !== 'string' && (val !== 'true' || val !== 'false')) { + throw Error(`Incorrect string value: ${val}`); + } + + return val === 'true'; +}; + program .option("-c --config ", "additional webpack configuration") .option("-p --port ", "port to serve from (default: 9000)") + .option("-b --babelrc ", "use .babelrc in root (default: true)", stringBooleanToBoolean) .option( "-t --timeout ", "function invocation timeout in seconds (default: 10)" @@ -57,8 +66,10 @@ program .description("build functions") .action(function(cmd, options) { console.log("netlify-lambda: Building functions"); + + const { config: userWebpackConfig, babelrc: useBabelrc = true} = program; build - .run(cmd, program.config) + .run(cmd, { userWebpackConfig, useBabelrc}) .then(function(stats) { console.log(stats.toString({ color: true })); }) diff --git a/lib/build.js b/lib/build.js index c64d695c..9b5a7824 100644 --- a/lib/build.js +++ b/lib/build.js @@ -31,7 +31,7 @@ function haveBabelrc(functionsDir) { ); } -function webpackConfig(dir, additionalConfig) { +function webpackConfig(dir, {userWebpackConfig, useBabelrc}) { var config = conf.load(); var envConfig = conf.loadContext(config).environment; var babelOpts = { cacheDirectory: true }; @@ -88,7 +88,7 @@ function webpackConfig(dir, additionalConfig) { ), use: { loader: require.resolve('babel-loader'), - options: babelOpts + options: {...babelOpts, babelrc: useBabelrc} } } ] @@ -129,8 +129,8 @@ function webpackConfig(dir, additionalConfig) { ` ); } - if (additionalConfig) { - var webpackAdditional = require(path.join(process.cwd(), additionalConfig)); + if (userWebpackConfig) { + var webpackAdditional = require(path.join(process.cwd(), userWebpackConfig)); return merge.smart(webpackConfig, webpackAdditional); }