A plugin for the serverless framework to bundle lambda code using rollup
npm install --save-dev serverless-rollup-plugin
Requires Node.js 18 and serverless 3.2.
Add the plugin to your serverless config:
plugins:
- serverless-rollup-plugin
- ...any other plugins
For each function that you would like to use rollup option, just define the handler option as normal. You can
optionally define the dependencies
property as a list of packages to be installed in the node_modules
folder
in your lambda.
testFunction:
handler: src/functions/testFunction/index.handler
dependencies:
- aws-xray-sdk-core
copyFiles:
- some/glob/**/*.pattern
By default, serverless-rollup-plugin
will attempt to load rollup.config.js
.
In order to override this behavior, you can add the following to configuration options:
custom:
rollup:
config: ./custom-rollup.config.js
By default if you specify function dependencies npm
will be used. You can override this by setting the installCommand
property, like this:
custom:
rollup:
installCommand: yarn add
If you want to add a dependency for every lambda function (for example adding source map support), you can add them to the rollup dependencies
property:
custom:
rollup:
dependencies:
- some-package-name
If you don't specify output
settings in your rollup config, the following defaults will be used:
{
"format": "cjs",
"sourcemap": true
}
If the format
is esm
, the resulting package will use the mjs
extension to make use of native lambda esm support.
By default, serverless-rollup-plugin
will output rollup bundles concurrently.
In systems with low memory, such as small CI instances, it may be necessary to limit the number concurrent outputs so as not to run out of memory.
You can define the number of concurrent outputs by using the concurrency
option:
custom:
rollup:
concurrency: 3
Any value other than a number will be treated as Number.POSITIVE_INFINITY
.
You can easily get your lambda stack traces to show correct file/line information using the source-map-support
package.
To use this with the serverless-rollup-plugin
, first install the package and add it to the universal dependencies:
custom:
rollup:
dependencies:
- source-map-support
Then in your rollup config, set the output banner to install it:
export default {
output: {
format: "cjs",
sourcemap: true,
banner: "require('source-map-support').install();"
}
};
If you do specify output
settings, they will be used and only the file
property will be overwritten.
To copy a static file into your function deployment, use the copyFiles
parameter. This
parameter is an array of glob pattern strings, or objects with the following properties:
Name | Required | Description |
---|---|---|
glob | Yes | A glob pattern |
srcBase | No | Part of the path that will be removed from the destination path |
destination | No | Destination path within the lambda's directory structure |
Julian Grinblat 💻 🚧 |
Ben Force 💻 📖 |
Vinicius Reis 💻 |
Jacky Shikerya 🐛 |
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator