serverless-rolldown
v0.0.5
Published
Serverless Framework v4 plugin that bundles Node.js Lambda handlers with Rolldown for packaging and local execution.
Readme
serverless-rolldown
Serverless Framework v4 plugin that bundles Node.js Lambda handlers with Rolldown for packaging and local execution.
What You Get
- Rolldown-powered builds for
serverless package,serverless deploy, andserverless deploy function - Local builds for
serverless invoke local,serverless invoke local --watch, andserverless-offline - Automatic loading of
rolldown.config.{js,mjs,cjs,ts,mts,cts}from the service root - Built-in Node/CommonJS defaults when no Rolldown config exists
- Handler rewriting in memory so Serverless points at the staged bundle output
- Separate output roots for package, invoke-local, and offline flows
- Local Node layer staging for local execution
Current Scope
- Serverless Framework v4
- Node.js Lambda handlers
- Single Rolldown config object exports
The plugin does not support Rolldown config arrays or config functions yet.
Quick Start
Install the plugin and its required peers in your Serverless service:
bun add -d serverless serverless-rolldown rolldown typescriptIf you also want local HTTP development with serverless-offline:
bun add -d serverless-offlineBefore using serverless-rolldown, disable Serverless Framework's built-in esbuild support:
build:
esbuild: falseThen add the plugin to serverless.yml:
service: my-service
frameworkVersion: ^4
build:
esbuild: false
provider:
name: aws
runtime: nodejs20.x
plugins:
- serverless-rolldown
- serverless-offline
functions:
hello:
handler: src/hello.handlerIf you leave esbuild enabled, Serverless and this plugin will both try to control the build step.
serverless-offline should come after serverless-rolldown in the plugin list.
Then use normal Serverless commands:
serverless package
serverless invoke local --function hello
serverless offlineOptional Config
custom:
rolldown:
configFile: ./rolldown.config.ts
outDir: ./.serverless/build
noBuild: false
noWatch: false
usePolling: falseSupported plugin options:
configFile?: stringoutDir?: stringnoBuild?: booleannoWatch?: booleanusePolling?: boolean | number
Defaults and CLI compatibility:
- Default
outDiris./.serverless/build --skip-build--rolldown-no-watch--rolldown-use-polling[=ms]
How Output Is Staged
- Package builds go under
<outDir>/package invoke localbuilds go under<outDir>/invoke-localserverless-offlinebuilds go under<outDir>/offline- Watched
serverless-offlineruns enablereloadHandlerautomatically so edited handlers are reloaded between requests
Rolldown Config Contract
The plugin owns a few parts of the final build shape:
input- Stage-specific output directories
- Handler mapping
- Node/CommonJS Lambda output mode
Your Rolldown config can still customize normal bundler behavior such as plugins, aliases, externals, and transforms.
Local Development
This repo uses Bun for development.
Install dependencies:
bun installCommon commands:
bun test
bun run typecheck
bun run build
bun run validate:examplebun run validate:example builds the plugin, installs the example app if needed, and runs the example smoke validation.
Example App
The example directory is a small Serverless v4 app wired to the local plugin build.
Useful commands inside example/:
bun install
bun run package
bun run invoke:hello
bun run dev
bun run validateUse bun run dev for local HTTP development with serverless-offline.
Notes
- Local layer support is Node-only, path-based, and copy-as-is
- Layer imports are treated as runtime externals when they resolve from referenced local layers
- Layer artifact packaging still relies on native Serverless behavior
Publishing
- Add an
NPM_TOKENrepository secret before using the publish workflow - Push a tag in the format
vX.Y.Zfrom the currentmainHEAD to trigger publish - The publish workflow updates
package.jsonfrom the tag version, then runsbun test,bun run typecheck, andbun run buildbeforenpm publish - If the tag version changed
package.json, the workflow commits that version back tomain
