sst / open-next

Open source Next.js serverless adapter
https://open-next.js.org
MIT License
3.73k stars 112 forks source link

[V3] Function splitting #327

Closed conico974 closed 2 months ago

conico974 commented 7 months ago

This PR add support for function splitting in open-next It is based on the rewrite server PR, if you want to review start at a50cdf7

Features

How to test

You'll need an open-next.config.ts file next to your next.config.js. A simple example of such a file:

import type { BuildOptions } from 'open-next/types/open-next'
const config = {
  default: {
    // debug: true,
    override: {
      wrapper: "aws-lambda-streaming",
    },
  },
  // functions: {},
  functions: {
    ssr: {
      routes: ["app/api/isr/route", "app/api/sse/route", "app/api/revalidateTag/route"],
      patterns: ['api/isr', 'api/sse', 'api/revalidateTag'],
      override: {
        wrapper: "aws-lambda-streaming",
      },
      experimentalBundledNextServer: true
    },
    pageSsr: {
      routes: ["pages/pageSsr"],
      patterns: [ 'pageSsr', "_next/data/BUILD_ID/pageSsr.json"],
      override: {
        wrapper: "node",
        converter: "node",
        generateDockerfile: true,
      },
    },
    edge: {
      // Edge runtime support only app dir routes and page
      runtime: "edge",
     // You could deploy edge runtime both "regional" or "global" (i.e. lambda@edge)
      placement: "regional",
      // Only one route at a time allowed for edge runtime
      routes: ["app/ssr/page"],
      patterns: ["ssr"],
      override: {}
    }

  },
  buildCommand: "echo 'hello world'"
} satisfies BuildOptions

module.exports = config;
export type OpenNextConfig = typeof config

You can now use the corresponding PR in sst to test this https://github.com/sst/sst/pull/3567

TODO

changeset-bot[bot] commented 7 months ago

⚠️ No Changeset found

Latest commit: 51ba372023f97462db65bb7a54947441aba5b9ca

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

vercel[bot] commented 7 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
open-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 6, 2024 9:00am