-
Notifications
You must be signed in to change notification settings - Fork 114
chore: deprecate #606
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
Merged
chore: deprecate #606
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# Migration Guide | ||
|
||
This guide covers the following use cases of netlify-lambda and how to accomplish them without this deprecated tool. | ||
|
||
- [Run Netlify functions locally](#run-netlify-functions-locally) | ||
- [Use Typescript or non-standard JavaScript features](#use-typescript-or-non-standard-javascript-features) | ||
- [Bundle with Webpack](#bundle-with-webpack) | ||
- [Install function dependencies](#install-function-dependencies) | ||
|
||
## Run Netlify Functions locally | ||
|
||
The tooling to run functions locally has been completely integrated into the Netlify CLI, which offers even more functionality like local debugging. | ||
|
||
If you had `netlify-lambda` in your npm scripts, you can migrate by changing to the Netlify CLI `dev` command. | ||
|
||
For example in a theoretical Gatsby project you can migrate with the following changes: | ||
|
||
> package.json | ||
|
||
```diff | ||
{ | ||
"scripts": { | ||
- "start:app": "npm run develop", | ||
- "start:lambda": "netlify-lambda serve src/lambda", | ||
- "start": "concurrently \"yarn start:lambda\" \"yarn develop\"", | ||
- "develop": "gatsby develop", | ||
+ "start": "netlify dev", | ||
}, | ||
"devDependencies": { | ||
- "netlify-lambda": "^1.4.3", | ||
+ "netlify-cli": "^10.14.0", | ||
} | ||
} | ||
``` | ||
|
||
## Use TypeScript or non-standard JavaScript features | ||
|
||
Netlify now supports TypeScript and non-standard JavaScript features. | ||
For TypeScript there is no configuration needed and it will work out of the box. The same is true if you use ESM modules in your functions. The bundling logic will automatically detect these and use `esbuild` or `nft` to bundle the functions. | ||
In any other case you can set the `node_bundler` to `esbuild` yourself for the functions in your `netlify.toml` file. https://docs.netlify.com/configure-builds/file-based-configuration/#functions | ||
|
||
Should `esbuild` not work for your use case then please report this to us or use webpack directly as described in the next section. | ||
|
||
## Bundle with Webpack | ||
|
||
If after trying our [automated bundling](#use-typescript-or-non-standard-javascript-features) you still want to use webpack to bundle your functions, you can use webpack directly and adjust the config to your needs. The following example is for webpack 4, which is the version that netlify-lambda used. | ||
|
||
> package.json | ||
|
||
```json | ||
{ | ||
"scripts":{ | ||
"build":"webpack --config ./webpack.config.js" | ||
} | ||
"devDependencies": { | ||
"webpack": "^4.46.0", | ||
"webpack-cli": "^4.10.0", | ||
"babel-loader": "^8.2.5", | ||
"@babel/preset-env": "^7.18.9", | ||
} | ||
} | ||
``` | ||
|
||
> webpack.config.js | ||
|
||
```js | ||
const webpack = require('webpack'); | ||
|
||
module.exports = { | ||
mode: 'production', | ||
resolve: { | ||
extensions: ['.wasm', '.mjs', '.js', '.json', '.ts'], | ||
mainFields: ['module', 'main'], | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(m?js|ts)?$/, | ||
exclude: new RegExp( | ||
`(node_modules|bower_components|\\.(test|spec)\\.?)`, | ||
), | ||
use: { | ||
loader: require.resolve('babel-loader'), | ||
options: { | ||
cacheDirectory: true, | ||
presets: [ | ||
[ | ||
require.resolve('@babel/preset-env'), | ||
{ targets: { node: '16.6.0' } }, | ||
], | ||
], | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
context: './src/functions', | ||
entry: {}, | ||
target: 'node', | ||
plugins: [new webpack.IgnorePlugin(/vertx/)], | ||
output: { | ||
path: './netlify/functions', | ||
filename: '[name].js', | ||
libraryTarget: 'commonjs', | ||
}, | ||
optimization: { | ||
nodeEnv: process.env.NODE_ENV || 'production', | ||
}, | ||
bail: true, | ||
devtool: false, | ||
stats: { | ||
colors: true, | ||
}, | ||
}; | ||
``` | ||
|
||
## Install function dependencies | ||
|
||
Consider moving the dependencies of your functions into your main `package.json` for automatic installation during local development. If this is not possible you can use the following change. | ||
|
||
Note that this is needed for local development only. The Netlify build system will detect and install dependencies of your functions. | ||
|
||
> package.json | ||
|
||
```diff | ||
{ | ||
"scripts": { | ||
- "postinstall": "netlify-lambda install", | ||
+ "postinstall": "npm --prefix ./functions/my-function i && npm --prefix ./functions/other-function i", | ||
}, | ||
"devDependencies": { | ||
- "netlify-lambda": "^1.4.3", | ||
} | ||
} | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.