serverless-rollup-plugin

5.0.1 • Public • Published

Welcome to serverless-rollup-plugin 👋

Release Maintainability npm version FOSSA Status All Contributors

A plugin for the serverless framework to bundle lambda code using rollup

Install

npm install --save-dev serverless-rollup-plugin

Requires Node.js 18 and serverless 3.2.

Usage

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

Config

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

Using Yarn

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

Add Global Dependency

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

Output Options

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.

Concurrency

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.

Adding Sourcemap Support

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.

Copying Resource Files

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

🧑‍💻 Contributors

🤝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator

Readme

Keywords

none

Package Sidebar

Install

npm i serverless-rollup-plugin

Weekly Downloads

134

Version

5.0.1

License

MIT

Unpacked Size

38.1 kB

Total Files

20

Last publish

Collaborators

  • benforce
  • jready