Vercel Edge Adaptor

Qwik City Vercel Edge adaptor allows you to connect Qwik City to Vercel Edge Functions.

Installation

To integrate the vercel-edge adaptor, use the add command:

npm run qwik add vercel-edge

It will automatically install the required dependencies, including the Vercel CLI.

The adaptor will add a new vite.config.ts within the adapters/ directory, and a new entry file will be created, such as:

โ””โ”€โ”€ adapters/
    โ””โ”€โ”€ vercel-edge/
        โ””โ”€โ”€ vite.config.ts
โ””โ”€โ”€ src/
    โ””โ”€โ”€ entry.vercel-edge.tsx

Additionally, within the package.json, the build.server and deploy scripts will be updated.

Production build

To build the application for production, use the build command, this command will automatically run npm run build.server and npm run build.client:

npm run build

Read the full guide here

Dev deploy

To deploy the application for development:

npm run deploy

Notice that you might need a Vercel account in order to complete this step!

Production deploy

After installing the integration using npm run qwik add vercel-edge, the project is ready to be deployed to Vercel. However, you will need to create a git repository and push the code to it.

Please refer to the Vercel docs for more information on how to deploy your site: Vercel docs

Advanced

Vercel Edge Entry Middleware

When the vercel-edge adaptor is added, a new entry file will be created at src/entry.vercel-edge.tsx. Below is an example of using the built-in middleware within the entry file.

// src/entry.vercel-edge.tsx
import { createQwikCity } from '@builder.io/qwik-city/middleware/vercel-edge';
import qwikCityPlan from '@qwik-city-plan';
import render from './entry.ssr';

export default createQwikCity({ render, qwikCityPlan });

The compiled middleware will be built in the .vercel/output directory.

Vercel Edge Functions

Vercel Edge Functions are deployed globally by default on Vercel's Edge Network and enable you to move server-side logic to the Edge, close to your visitor's origin.

Edge Functions use the Vercel Edge Runtime, which is built on the same high-performance V8 JavaScript and WebAssembly engine that is used by the Chrome browser. By taking advantage of this small runtime, Edge Functions can have faster cold boots and higher scalability than Serverless Functions.

Edge Functions run after the cache, and can both cache and return responses.

Made with โค๏ธ by