Skip to content

Commit

Permalink
Merge pull request #154 from omonk/add-babelrc-flag
Browse files Browse the repository at this point in the history
Add flag to not use relative .babelrc config
  • Loading branch information
swyxio authored May 18, 2019
2 parents ccf83b1 + 0fd4b18 commit 86332fb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ The additional webpack config will be merged into the default config via [webpac

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).

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.
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.

It is possible to disable this behaviour by passing `--babelrc false`.

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.

Expand Down Expand Up @@ -393,6 +395,7 @@ There are additional CLI options:
-p --port
-s --static
-t --timeout
-b --babelrc
```

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

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).

### --babelrc

Defaults to `true`

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)

## Netlify Identity

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).
Expand Down
14 changes: 13 additions & 1 deletion bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ var serve = require("../lib/serve");

program.version(pkg.version);

const stringBooleanToBoolean = val => {
console.log({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 <babelrc>", "use .babelrc in root (default: true)", stringBooleanToBoolean)
.option(
"-t --timeout <timeout>",
"function invocation timeout in seconds (default: 10)"
Expand Down Expand Up @@ -63,8 +73,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 @@ -130,8 +130,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 86332fb

Please sign in to comment.