Adds Vercel adapters for server-side rendering

This commit is contained in:
Alicia Sykes 2024-02-10 20:58:55 +00:00
parent 6e2881117e
commit 71139bc236
7 changed files with 4438 additions and 43 deletions

3
web/.gitignore vendored
View File

@ -39,3 +39,6 @@ lerna-debug.log*
# Yarn
.yarn/*
!.yarn/releases
# Vercel
.vercel

View File

@ -63,3 +63,47 @@ The production build will generate client and server modules by running both cli
```shell
yarn build # or `yarn build`
```
## Vercel Edge
This starter site is configured to deploy to [Vercel Edge Functions](https://vercel.com/docs/concepts/functions/edge-functions), which means it will be rendered at an edge location near to your users.
## Installation
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` script will be updated with the Vercel Edge build.
## 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`:
```shell
npm run build
```
[Read the full guide here](https://github.com/BuilderIO/qwik/blob/main/starters/adapters/vercel-edge/README.md)
## Dev deploy
To deploy the application for development:
```shell
npm run deploy
```
Notice that you might need a [Vercel account](https://docs.Vercel.com/get-started/) in order to complete this step!
## Production deploy
The project is ready to be deployed to Vercel. However, you will need to create a git repository and push the code to it.
You can [deploy your site to Vercel](https://vercel.com/docs/concepts/deployments/overview) either via a Git provider integration or through the Vercel CLI.

View File

@ -0,0 +1,16 @@
import { vercelEdgeAdapter } from "@builder.io/qwik-city/adapters/vercel-edge/vite";
import { extendConfig } from "@builder.io/qwik-city/vite";
import baseConfig from "../../vite.config.mts";
export default extendConfig(baseConfig, () => {
return {
build: {
ssr: true,
rollupOptions: {
input: ["src/entry.vercel-edge.tsx", "@qwik-city-plan"],
},
outDir: ".vercel/output/functions/_qwik-city.func",
},
plugins: [vercelEdgeAdapter()],
};
});

View File

@ -1,12 +1,13 @@
{
"license": "MIT",
"scripts": {
"dev": "vite --mode ssr",
"build": "qwik build",
"build.client": "vite build",
"build.preview": "vite build --ssr src/entry.preview.tsx",
"build.server": "vite build -c adapters/vercel-edge/vite.config.mts",
"build.types": "tsc --incremental --noEmit",
"deploy": "echo 'Run \"npm run qwik add\" to install a server adapter'",
"deploy": "vercel deploy",
"dev": "vite --mode ssr",
"dev.debug": "node --inspect-brk ./node_modules/vite/bin/vite.js --mode ssr --force",
"fmt": "prettier --write .",
"fmt.check": "prettier --check .",
@ -30,6 +31,7 @@
"tailwindcss": "^3.2.4",
"typescript": "^5.3.3",
"undici": "^5.16.0",
"vercel": "^29.1.1",
"vite": "^4.0.4",
"vite-plugin-static-copy": "^1.0.1",
"vite-tsconfig-paths": "^4.3.1"

View File

@ -0,0 +1,22 @@
/*
* WHAT IS THIS FILE?
*
* It's the entry point for Vercel Edge when building for production.
*
* Learn more about the Vercel Edge integration here:
* - https://qwik.builder.io/docs/deployments/vercel-edge/
*
*/
import {
createQwikCity,
type PlatformVercel,
} from "@builder.io/qwik-city/middleware/vercel-edge";
import qwikCityPlan from "@qwik-city-plan";
import { manifest } from "@qwik-client-manifest";
import render from "./entry.ssr";
declare global {
interface QwikCityPlatform extends PlatformVercel {}
}
export default createQwikCity({ render, qwikCityPlan, manifest });

13
web/vercel.json Normal file
View File

@ -0,0 +1,13 @@
{
"headers": [
{
"source": "/build/(.*)",
"headers": [
{
"key": "Cache-Control",
"value": "public, max-age=31536000, s-maxage=31536000, immutable"
}
]
}
]
}

File diff suppressed because it is too large Load Diff