-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from beforeyoubid/feature/initial-code
changed version
- Loading branch information
Showing
4 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "serverless-esbuild-layers", | ||
"version": "1.0.0", | ||
"version": "0.1.0", | ||
"author": { | ||
"name": "Bailey Sheather", | ||
"email": "[email protected]", | ||
|
@@ -9,6 +9,9 @@ | |
"license": "MIT", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist/**/*" | ||
], | ||
"scripts": { | ||
"test": "jest --coverage --passWithNoTests", | ||
"lint": "eslint '**/*.{ts,tsx,js,jsx}' --max-warnings 0", | ||
|
This file contains 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 |
---|---|---|
@@ -1 +1,84 @@ | ||
# serverless-esbuild-layers | ||
# serverless-esbuild-layers | ||
|
||
Plugin for the [Serverless framework][serverless] that allows you to leverage Lambda layers to separate your node modules into layers attached to relevant functions. | ||
|
||
This helps to keep the overall function size down. | ||
|
||
This library is designed to be used in conjuction with [serverless-esbuild][serverless-esbuild] to build your code. | ||
|
||
![Diagram](./docs/diagram.png) | ||
|
||
## Installation | ||
|
||
```sh | ||
yarn add --dev serverless-esbuild-layers serverless-esbuild esbuild-node-externals | ||
npm install --save-dev serverless-esbuild-layers serverless-esbuild esbuild-node-externals | ||
pnpm install --dev serverless-esbuild-layers serverless-esbuild esbuild-node-externals | ||
``` | ||
|
||
### Setup | ||
Once installed, you need to add this to your serverless plugins: | ||
|
||
```yaml | ||
plugins: | ||
- serverless-esbuild | ||
- serverless-esbuild-layers | ||
``` | ||
You also need to configure `serverless-esbuild` to externalise all node modules: | ||
|
||
```yaml | ||
custom: | ||
esbuild: | ||
plugins: esbuild-plugins.js | ||
exclude: | ||
- '*' | ||
``` | ||
|
||
the [serverless-esbuild][esbuild-plugins] library supports custom plugins to configure esbuild. In order to leverage this library, you need to use [esbuild-node-externals][esbuild-node-externals] to externalise all node modules | ||
|
||
```js | ||
const { nodeExternalsPlugin } = require('esbuild-node-externals'); | ||
module.exports = [nodeExternalsPlugin()]; | ||
``` | ||
|
||
### Adding layers | ||
|
||
Once the plugin is configured in your serverless file, you need to add Layer definitions to your serverless file: | ||
|
||
```yaml | ||
layers: | ||
lib: | ||
path: '.serverless' | ||
name: my-modules | ||
description: node_modules | ||
compatibleRuntimes: | ||
- nodejs14.x | ||
``` | ||
|
||
Then you can reference the relevant layers in each function (the ref should match `NameLambdaLayer` where name is the key of your layer with the first character uppercase) | ||
```yaml | ||
functions: | ||
test: | ||
handler: handler.default | ||
layers: | ||
- { Ref: LibLambdaLayer } | ||
``` | ||
|
||
If you have multiple functions, it's recommended to add different layers depending on node module overlap. This library will identify which modules are needed by all the functions attached to each layer. | ||
|
||
## Config | ||
|
||
This library can be configured by adding options into your serverless file: | ||
|
||
```yaml | ||
custom: | ||
esbuild-layers: | ||
packager: 'auto' # can be specified as 'npm' | 'yarn' | 'pnpm'; | ||
``` | ||
|
||
[serverless]: https://www.serverless.com/ | ||
[serverless-esbuild]: https://github.com/floydspace/serverless-esbuild | ||
[esbuild-plugins]: https://github.com/floydspace/serverless-esbuild#esbuild-plugins | ||
[esbuild-node-externals]: https://github.com/pradel/esbuild-node-externals |