发布你的 Web 应用

了解如何使用 EAS Hosting 部署你的 Web 应用。


EAS Hosting 处于预览阶段,可能会发生变化。

如果你正在构建通用应用,则可以使用 EAS 托管 快速部署你的 Web 应用。它是一种用于部署使用 Expo Router 和 React 构建的 Web 应用的服务。

¥If you are building a universal app, you can quickly deploy your web app using EAS Hosting. It is a service for deploying web apps built with Expo Router and React.

先决条件

¥Prerequisites

开始之前,在项目的 app.json 文件中,确保 expo.web.output 属性为 staticserver

¥Before you begin, in your project's app.json file, ensure that the expo.web.output property is either static or server.

导出你的 Web 项目

¥Export your web project

要部署你的 Web 应用,你需要创建 Web 项目的静态构建。通过运行以下命令将你的 Web 项目导出到 dist 目录中:

¥To deploy your web app, you need to create a static build of your web project. Export your web project into a dist directory by running the following command:

Terminal
npx expo export --platform web

请记住,每次在部署之前对 Web 应用进行更改时,都要重新运行此命令。

¥Remember to re-run this command every time before deploying when you make changes to your web app.

初始部署

¥Initial deployment

要发布你的 Web 应用,请运行以下 EAS 命令行接口 命令:

¥To publish your web app, run the following EAS CLI command:

Terminal
eas deploy

首次运行此命令后,系统将提示你为项目选择一个预览子域。此子域是用于创建预览 URL 的前缀,用于生产部署。例如,在 https://test-app--1234.expo.app 中,test-app 是预览子域。

¥After running this command for the first time, you'll be prompted to select a preview subdomain for your project. This subdomain is a prefix used to create a preview URL and is used for production deployments. For example, in https://test-app--1234.expo.app, test-app is the preview subdomain.

部署完成后,EAS CLI 将输出预览 URL 以访问你部署的应用。

¥Once your deployment is complete, the EAS CLI will output a preview URL to access your deployed app.

生产部署

¥Production deployment

要创建生产部署,请运行以下 EAS 命令行接口 命令:

¥To create a production deployment, run the following EAS CLI command:

Terminal
eas deploy --prod

部署完成后,EAS CLI 将输出生产 URL 以访问你部署的应用。

¥Once your deployment is complete, the EAS CLI will output a production URL to access your deployed app.

了解更多

¥Learn more

你可以了解有关设置 部署别名、使用 自定义域部署 API 路由 的更多信息。

¥You can learn more about setting up deployment aliases, using a custom domain, or deploying an API Route.