Skip to content

Commit 9117c36

Browse files
committed
add new flag to opt out of default babelrc loading
1 parent 7ab1220 commit 9117c36

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
2+
.vscode/
23
*.swp

Diff for: bin/cmd.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,18 @@ var serve = require("../lib/serve");
1515

1616
program.version(pkg.version);
1717

18+
const stringBooleanToBoolean = val => {
19+
if (typeof val !== 'string' && (val !== 'true' || val !== 'false')) {
20+
throw Error(`Incorrect string value: ${val}`);
21+
}
22+
23+
return val === 'true';
24+
};
25+
1826
program
1927
.option("-c --config <webpack-config>", "additional webpack configuration")
2028
.option("-p --port <port>", "port to serve from (default: 9000)")
29+
.option("-b --babelrc <no-babelrc>", "use .babelrc in root (default: true)", stringBooleanToBoolean)
2130
.option(
2231
"-t --timeout <timeout>",
2332
"function invocation timeout in seconds (default: 10)"
@@ -57,8 +66,10 @@ program
5766
.description("build functions")
5867
.action(function(cmd, options) {
5968
console.log("netlify-lambda: Building functions");
69+
70+
const { config: userWebpackConfig, babelrc: useBabelrc = true} = program;
6071
build
61-
.run(cmd, program.config)
72+
.run(cmd, { userWebpackConfig, useBabelrc})
6273
.then(function(stats) {
6374
console.log(stats.toString({ color: true }));
6475
})

Diff for: lib/build.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function haveBabelrc(functionsDir) {
3131
);
3232
}
3333

34-
function webpackConfig(dir, additionalConfig) {
34+
function webpackConfig(dir, {userWebpackConfig, useBabelrc}) {
3535
var config = conf.load();
3636
var envConfig = conf.loadContext(config).environment;
3737
var babelOpts = { cacheDirectory: true };
@@ -88,7 +88,7 @@ function webpackConfig(dir, additionalConfig) {
8888
),
8989
use: {
9090
loader: require.resolve('babel-loader'),
91-
options: babelOpts
91+
options: {...babelOpts, babelrc: useBabelrc}
9292
}
9393
}
9494
]
@@ -129,8 +129,8 @@ function webpackConfig(dir, additionalConfig) {
129129
`
130130
);
131131
}
132-
if (additionalConfig) {
133-
var webpackAdditional = require(path.join(process.cwd(), additionalConfig));
132+
if (userWebpackConfig) {
133+
var webpackAdditional = require(path.join(process.cwd(), userWebpackConfig));
134134

135135
return merge.smart(webpackConfig, webpackAdditional);
136136
}

0 commit comments

Comments
 (0)