We can deploy vite-plugin-ssr
to Vercel simply by using a Vercel API Route, or we can use vite-plugin-vercel
if we want advanced Vercel features such as ISR and Edge Middleware.
We can deploy our vite-plugin-ssr
app to Vercel simply by creating a Vercel API Route api/ssr.js
that server-side renders our app.
Example: github.com/brillout/vite-plugin-ssr_vercel.
Make sure to properly set
OUTPUT DIRECTORY
in your Vercel dashboard, see the example'sreadme.md
instructions.
Using a Vercel API Route is a sturdy way to deploy to Vercel as API Routes is a core Vercel feature: it's here to stay and, most importantly, stable. (Whereas Vercel's Build Output API is a moving target with occasional breaking changes.) Once we setup our server-side rendering API Route, we can expect it to work for the foreseeable future.
vite-plugin-vercel
enables zero-configuration support for all Vercel features, including Incremental Static Regeneration (ISR) and Edge Middleware.
If we pre-render our pages only partially, we can also use vite-plugin-vercel
to statically deploy our pre-rendered pages while dynamically serving our non-prerendered pages.
See
vite-plugin-ssr
+vite-plugin-vercel
installation instructions atvite-plugin-vercel
> Usage with vite-plugin-ssr.
Under the hood,
vite-plugin-vercel
uses Vercel's Build Output API.
For maximum flexibility and configuration options, we can also directly use the Build Output API.
Example: github.com/brillout/vite-plugin-ssr_vercel_build-output-api.
Vercel API Routes only work on Vercel's platform; we cannot run them locally.
This means that we need to integrate our data layer twice:
This is usally easy to achieve as most data layer tools integrate using a single HTTP endpoint. For example:
/graphql
./_telefunc
.In other words, we add a data layer by:
When using SSR, we recommend using RPC instead of GraphQL, which most of time leads to a drastic simplification and increased development speed.