Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag to not use relative .babelrc config #154

Merged
merged 3 commits into from
May 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -57,8 +67,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