概览


¥Overview

了解更多关于 Nitro 部署提供商的信息。

Nitro 可以从同一代码库生成适用于不同托管服务提供商的不同输出格式。使用内置预设,你可以轻松地配置 Nitro 以调整其输出格式,几乎无需任何额外的代码或配置!

¥Nitro can generate different output formats suitable for different hosting providers from the same code base. Using built-in presets, you can easily configure Nitro to adjust its output format with almost no additional code or configuration!

默认输出

¥Default output

默认生产输出预设为 Node.js 服务器

¥The default production output preset is Node.js server.

在开发模式下运行 Nitro 时,Nitro 将始终使用名为 nitro-dev 的特殊预设,在隔离的工作环境中使用带有 ESM 的 Node.js,其行为尽可能接近生产环境。

¥When running Nitro in development mode, Nitro will always use a special preset called nitro-dev using Node.js with ESM in an isolated Worker environment with behavior as close as possible to the production environment.

零配置提供程序

¥Zero-Config Providers

使用 CI/CD 部署到生产环境时,Nitro 会尝试自动检测提供程序环境并设置正确的环境,无需任何额外配置。目前,以下提供程序可以在零配置的情况下自动检测。

¥When deploying to production using CI/CD, Nitro tries to automatically detect the provider environment and set the right one without any additional configuration required. Currently, the providers below can be auto-detected with zero config.

::warning 对于 Turborepo 用户,零配置检测将受到其严格环境模式的干扰。你可能需要明确允许变量,或使用其松散环境模式(带有 --env-mode=loose 标志)。::

¥::warning For Turborepo users, zero config detection will be interferenced by its Strict Environment Mode. You may need to allowing the variables explictly or use its Loose Environment Mode (with --env-mode=loose flag). ::

更改部署预设

¥Changing the deployment preset

如果你需要针对特定​​提供程序构建 Nitro,可以通过定义名为 NITRO_PRESETSERVER_PRESET 的环境变量,或者更新 Nitro configuration 或使用 --preset 参数来定位它。

¥If you need to build Nitro against a specific provider, you can target it by defining an environment variable named NITRO_PRESET or SERVER_PRESET, or by updating your Nitro configuration or using --preset argument.

对于依赖于 CI/CD 的部署,建议使用环境变量方法。

¥Using the environment variable approach is recommended for deployments depending on CI/CD.

示例:定义 NITRO_PRESET 环境变量

¥Example: Defining a NITRO_PRESET environment variable

nitro build --preset cloudflare_pages

示例:更新 nitro.config.ts 文件

¥Example: Updating the nitro.config.ts file

export default defineNitroConfig({
  preset: 'cloudflare_pages'
})