@nikso/adapter-serverless
v0.1.0
Published
An (experimental) adapter to build a [SvelteKit](https://kit.svelte.dev/) app into a lambda ready handler for [Serverless](https://www.serverless.com/) deployment.
Downloads
2
Readme
adapter-serverless for SvelteKit
An (experimental) adapter to build a SvelteKit app into a lambda ready handler for Serverless deployment.
npm install --save-dev @nikso/adapter-serverless
It uses serverless-http to wrap a Polka server.
Note that because of the ESM nature of SvelteKit and the non-ESM nature of AWS lamnda, this adapter uses esbuild to compile your app in a CommonJS bundle.
Usage
In your svelte.config.cjs
add the adapter like so:
const serverless = require('@nikso/adapter-serverless');
const pkg = require('./package.json');
module.exports = {
kit: {
adapter: serverless(),
// NOTE that Serverless might add a "stage" fragment to URLs. You want to
// reflect it here in `path.base` to have static files being served properly
paths: {
base: '/dev',
},
target: '#svelte',
vite: {
ssr: {
noExternal: Object.keys(pkg.dependencies || {}),
},
},
},
};
Example serverless.yml
After building your Svelte app with npm run build
, an example Serverless
configuration to run serverless offline
could be:
service: svelte-app
frameworkVersion: '2'
provider:
name: aws
runtime: nodejs12.x
lambdaHashingVersion: 20201221
package:
individually: true
exclude:
- ./**
include:
- build/**
functions:
svelte:
handler: build/serverless.handler
events:
- http: ANY /
- http: ANY /{proxy+}
plugins:
- serverless-offline