Providers

Netlify

将 Nitro 应用部署到 Netlify Functions 或 Edge。

预设:netlify

¥Preset: netlify

Read more in Netlify Functions.
zero configuration 可以与此提供程序集成。

通常,部署到 Netlify 不需要任何配置。Nitro 将自动检测你是否处于 Netlify 构建环境中,并构建正确版本的服务器。

¥Normally, the deployment to Netlify does not require any configuration. Nitro will auto-detect that you are in a Netlify build environment and build the correct version of your server.

要启用 Netlify Functions 2.0 并使用其功能(例如流式响应和 Netlify Blob),你需要在 nitro 配置文件中将兼容日期设置为 2024-05-07 或更高版本。

¥To enabling Netlify Functions 2.0 and using its features (e.g. streaming responses and Netlify Blobs), you need a compatibility date set to 2024-05-07 or later in your nitro configuration file.

export default defineNitroConfig({
    compatibilityDate: "2024-05-07",
})

对于新网站,Netlify 会检测到你正在使用 Nitro,并将发布目录设置为 dist,构建命令设置为 npm run build

¥For new sites, Netlify will detect that you are using Nitro and set the publish directory to dist and build command to npm run build.

如果你要升级现有网站,请检查这些内容并在必要时进行更新。

¥If you are upgrading an existing site you should check these and update them if needed.

如果你想添加自定义重定向,可以使用 routeRules 或将 _redirects 文件添加到你的 public 目录。

¥If you want to add custom redirects, you can do so with routeRules or by adding a _redirects file to your public directory.

部署时,只需将其推送到你的 git 仓库 与 Netlify 的常规操作相同 即可。

¥For deployment, just push to your git repository as you would normally do for Netlify.

创建新项目时,请确保将发布目录设置为 dist

Netlify 边缘函数

¥Netlify edge functions

预设:netlify_edge

¥Preset: netlify_edge

Netlify Edge Functions 使用 Deno 和强大的 V8 JavaScript 运行时,让你可以运行全局分布式函数,以实现最快的响应时间。

¥Netlify Edge Functions use Deno and the powerful V8 JavaScript runtime to let you run globally distributed functions for the fastest possible response times.

Read more in Netlify Edge functions.

Nitro 输出可以直接在边缘运行服务器。更贴近你的用户。

¥Nitro output can directly run the server at the edge. Closer to your users.

创建新项目时,请确保将发布目录设置为 dist

按需构建器

¥On-demand builders

预设:netlify_builder

¥Preset: netlify_builder

::warning 注意:此预设已弃用。请改用 netlify 预设和 isr 路由规则。::

¥::warning Note: This preset is deprecated. Instead, use the netlify preset with the isr route rule. ::

按需构建器是无服务器函数,用于根据需要生成 Web 内容,并自动缓存在 Netlify 的 Edge CDN 上。它们使你能够在用户首次访问网站时为其构建页面,然后将其缓存在边缘以供后续访问。

¥On-demand Builders are serverless functions used to generate web content as needed that’s automatically cached on Netlify’s Edge CDN. They enable you to build pages for your site when a user visits them for the first time and then cache them at the edge for subsequent visits.

Read more in Netlify On-demand Builders.

自定义部署配置

¥Custom deploy configuration

你可以使用 nitro.config 中的 netlify 键提供额外的部署配置。它将与内置的自动生成的配置合并。目前,对于 配置 Netlify 镜像 CDN,唯一支持的值是 images.remote_images

¥You can provide additional deploy configuration using the netlify key inside nitro.config. It will be merged with built-in auto-generated config. Currently the only supported value is images.remote_images, for configuring Netlify Image CDN.