Vercel

To deploy a vite-plugin-ssr app to Vercel we:

  • Load dist/server/importBuild.js in our Vercel serverless function (e.g. /examples/vercel/api/render.js).
  • Run our build script (vite build && vite build --ssr) in package.json#scripts['vercel-build'] instead of package.json#scripts.build.
  • In the Vercel web UI, set the OUTPUT DIRECTORY config of your Vercel app to dist/client (and make to sure enable OVERRIDE).

Vercel bundles serverless functions behind the scenes; dist/server/importBuild.js helps bundlers discover the entire dependency tree.

Vercel discards all files generated by the package.json#scritps.build script. That's why we use package.json#scripts['vercel-build'] instead.

More infos:

To increase build caching performance, Vercel recommends using yarn instead of npm.

Example:

Edit this page