Skip to content

Commit 86332fb

Browse files
authored
Merge pull request #154 from omonk/add-babelrc-flag
Add flag to not use relative .babelrc config
2 parents ccf83b1 + 0fd4b18 commit 86332fb

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

.gitignore

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

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,9 @@ The additional webpack config will be merged into the default config via [webpac
347347

348348
The default webpack configuration uses `babel-loader` with a [few basic settings](https://github.com/netlify/netlify-lambda/blob/master/lib/build.js#L19-L33).
349349

350-
However, if any `.babelrc` is found in the directory `netlify-lambda` is run from, or [folders above it](https://github.com/netlify/netlify-lambda/pull/92) (useful for monorepos), it will be used instead of the default one.
350+
However, if any `.babelrc` is found in the directory `netlify-lambda` is run from, or [folders above it](https://github.com/netlify/netlify-lambda/pull/92) (useful for monorepos), it will be used instead of the default one.
351+
352+
It is possible to disable this behaviour by passing `--babelrc false`.
351353

352354
If you need to run different babel versions for your lambda and for your app, [check this issue](https://github.com/netlify/netlify-lambda/issues/34) to override your webpack babel-loader.
353355

@@ -393,6 +395,7 @@ There are additional CLI options:
393395
-p --port
394396
-s --static
395397
-t --timeout
398+
-b --babelrc
396399
```
397400

398401
### --config option
@@ -422,6 +425,12 @@ The serving port can be changed with the `-p`/`--port` option.
422425

423426
If you need an escape hatch and are building your lambda in some way that is incompatible with our build process, you can skip the build with the `-s` or `--static` flag. [More info here](https://github.com/netlify/netlify-lambda/pull/62).
424427

428+
### --babelrc
429+
430+
Defaults to `true`
431+
432+
Use a `.babelrc` found in the directory `netlify-lambda` is run from. This can be useful when you have conflicting babel-presets, more info [here](#babel-configuration)
433+
425434
## Netlify Identity
426435

427436
Make sure to [read the docs](https://www.netlify.com/docs/functions/#identity-and-functions) on how Netlify Functions and Netlify Identity work together. Basically you have to make your request with an `authorization` header and a `Bearer` token with your Netlify Identity JWT supplied. You can get this JWT from any of our Identity solutions from [gotrue-js](https://github.com/netlify/gotrue-js) to [netlify-identity-widget](https://github.com/netlify/netlify-identity-widget).

bin/cmd.js

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

1616
program.version(pkg.version);
1717

18+
const stringBooleanToBoolean = val => {
19+
console.log({val});
20+
if (typeof val !== 'string' && (val !== 'true' || val !== 'false')) {
21+
throw Error(`Incorrect string value: ${val}`);
22+
}
23+
24+
return val === 'true';
25+
};
26+
1827
program
1928
.option("-c --config <webpack-config>", "additional webpack configuration")
2029
.option("-p --port <port>", "port to serve from (default: 9000)")
30+
.option("-b --babelrc <babelrc>", "use .babelrc in root (default: true)", stringBooleanToBoolean)
2131
.option(
2232
"-t --timeout <timeout>",
2333
"function invocation timeout in seconds (default: 10)"
@@ -63,8 +73,10 @@ program
6373
.description("build functions")
6474
.action(function(cmd, options) {
6575
console.log("netlify-lambda: Building functions");
76+
77+
const { config: userWebpackConfig, babelrc: useBabelrc = true} = program;
6678
build
67-
.run(cmd, program.config)
79+
.run(cmd, { userWebpackConfig, useBabelrc})
6880
.then(function(stats) {
6981
console.log(stats.toString({ color: true }));
7082
})

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
]
@@ -130,8 +130,8 @@ function webpackConfig(dir, additionalConfig) {
130130
`
131131
);
132132
}
133-
if (additionalConfig) {
134-
var webpackAdditional = require(path.join(process.cwd(), additionalConfig));
133+
if (userWebpackConfig) {
134+
var webpackAdditional = require(path.join(process.cwd(), userWebpackConfig));
135135

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

0 commit comments

Comments
 (0)