Skip to content

Commit

Permalink
add new flag to opt out of default babelrc loading
Browse files Browse the repository at this point in the history
  • Loading branch information
omonk committed May 17, 2019
1 parent 7ab1220 commit 9117c36
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.vscode/
*.swp
13 changes: 12 additions & 1 deletion bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <webpack-config>", "additional webpack configuration")
.option("-p --port <port>", "port to serve from (default: 9000)")
.option("-b --babelrc <no-babelrc>", "use .babelrc in root (default: true)", stringBooleanToBoolean)
.option(
"-t --timeout <timeout>",
"function invocation timeout in seconds (default: 10)"
Expand Down Expand Up @@ -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 }));
})
Expand Down
8 changes: 4 additions & 4 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -88,7 +88,7 @@ function webpackConfig(dir, additionalConfig) {
),
use: {
loader: require.resolve('babel-loader'),
options: babelOpts
options: {...babelOpts, babelrc: useBabelrc}
}
}
]
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 9117c36

Please sign in to comment.