Vercel
预设:vercel
¥Preset: vercel
使用 git 部署
¥Deploy using git
- 将你的代码推送到你的 git 仓库(GitHub、GitLab、Bitbucket)。
- 导入你的项目 导入 Vercel。
- Vercel 将检测到你正在使用 Nitro,并为你的部署启用正确的设置。
- 你的应用已部署!
项目导入并部署后,所有后续推送到分支的操作都将生成 预览部署,对生产分支(通常为“main”)所做的所有更改都将生成 生产环境部署。
¥After your project has been imported and deployed, all subsequent pushes to branches will generate Preview Deployments, and all changes made to the Production Branch (commonly “main”) will result in a Production Deployment.
了解更多关于 Vercel Git 集成 的信息。
¥Learn more about Vercel’s Git Integration.
Monorepo
Vercel 支持 Monorepos。但是,必须在 "项目设置 > 常规" 选项卡中指定自定义“根目录”。确保已选中 "包含根目录之外的源文件"。
¥Monorepos are supported by Vercel. However a custom "Root Directory" must be specified in "Project Settings > General" tab. Make sure that "Include source files outside of the Root Directory" is checked.
"根目录" 值的示例:apps/web
或 packages/app
。
¥Examples of values for "Root Directory": apps/web
or packages/app
.
API 路由
¥API routes
Nitro /api
目录与 Vercel 不兼容。你应该使用:
¥Nitro /api
directory isn't compatible with Vercel. Instead, you should use:
server/routes/api/
独立使用
自定义构建输出配置
¥Custom build output configuration
你可以使用 nitro.config
中的 vercel.config
键提供额外的 构建输出配置。它将与内置的自动生成的配置合并。
¥You can provide additional build output configuration using vercel.config
key inside nitro.config
. It will be merged with built-in auto-generated config.
按需增量静态再生 (ISR)
¥On-Demand incremental static regeneration (ISR)
按需重新验证允许你随时清除 ISR 路由的缓存,从而省去了后台重新验证所需的时间间隔。
¥On-demand revalidation allows you to purge the cache for an ISR route whenever you want, foregoing the time interval required with background revalidation.
要按需重新验证页面:
¥To revalidate a page on demand:
- 你可以使用命令
openssl rand -base64 32
或 生成密钥 生成随机值。
export default defineNitroConfig({
vercel: {
config: {
bypassToken: process.env.VERCEL_BYPASS_TOKEN
}
}
})
bypassToken
。当使用此标头集访问该预渲染函数端点时,缓存将被重新验证。对该函数的下一个请求应返回一个新的响应。通过路由规则进行细粒度的 ISR 配置
¥Fine-grained ISR config via route rules
默认情况下,查询参数会被缓存忽略。
¥By default, query paramas are ignored by cache.
你可以将选项对象传递给 isr
路由规则来配置缓存行为。
¥You can pass an options object to isr
route rule to configure caching behavior.
expiration
:调用无服务器函数重新生成缓存资源之前的过期时间(以秒为单位)。将值设置为false
(或isr: true
路由规则)意味着它永不过期。group
:资源的组编号。具有相同组号的预渲染资源将同时重新验证。allowQuery
:将单独缓存的查询字符串参数名称列表。- 如果数组为空,则查询值不会被缓存。
- 如果
undefined
,则每个唯一查询值都被独立缓存。 - 对于通配符
/**
路由规则,始终会添加url
。
passQuery
:当true
选项启用时,查询字符串将出现在传递给被调用函数的request
参数中。allowQuery
过滤器仍然适用。
export default defineNitroConfig({
routeRules: {
"/products/**": {
isr: {
allowQuery: ["q"],
passQuery: true,
},
},
},
});
Vercel Edge Functions
预设:vercel_edge
(已弃用)
¥Preset: vercel_edge
(deprecated)
我们建议迁移到默认的 Node.js 运行时并启用 流体计算。
¥We recommend migrating to the default Node.js runtime and enabling Fluid compute.