Skip to content

thenikso/adapter-serverless

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A SvelteKit adapter to build for Serverless

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published