serverless-rollup-plugin

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

Usage no npm install needed!

<script type="module">
  import serverlessRollupPlugin from 'https://cdn.skypack.dev/serverless-rollup-plugin';
</script>

README

Welcome to serverless-rollup-plugin 👋

Release Maintainability npm version FOSSA Status

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

Install

yarn install serverless-rollup-plugin

Usage

Add the plugin to your serverless config:

plugins:
  - serverless-rollup-plugin
  - ...any other plugins

Under the custom property, add a section for rollup. The only required property to run rollup is the config property:

custom:
  rollup:
    config: ./rollup.config.js

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

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
}

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

Author

👤 Ben Force

🤝 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