EAS Hosting 简介
EAS Hosting 是一项用于快速部署使用 Expo Router 库和 React Native web 构建的网页项目的服务。
EAS托管 是 EAS(Expo 应用服务)提供的一项服务,用于快速部署使用 Expo Router 和 React Native web 构建的 Web 项目。它与 Expo CLI 无缝集成,使你可以自动化部署 API 路由、服务器功能和服务器端资源。
EAS Hosting 提供了从 npx create-expo-app 到完全部署的 Web 应用(包含 API 路由和服务器功能)的最快路径。
🌐 EAS Hosting offers the fastest path from npx create-expo-app to a fully deployed web app with API routes and server functions.
快速开始
🌐 Quick start
信息 以下
eas命令需要 EAS CLI。有关更多信息,请参阅 如何安装 EAS CLI。
要部署你的网页应用,你需要创建网页项目的静态构建版本。运行以下命令将你的网页项目导出到 dist 目录中:
🌐 To deploy your web app, you need to create a static build of your web project. Run the following command to export your web project into a dist directory:
- npx expo export --platform web要发布你的网页应用,请运行以下命令:
🌐 To publish your web app, run the following command:
- eas deploy一旦部署完成,EAS CLI 将输出一个预览 URL,用于访问你已部署的网页应用。
🌐 Once your deployment is complete, the EAS CLI will output a preview URL to access your deployed web app.
为什么选择 EAS 托管
🌐 Why EAS Hosting
从历史上看,传统的网站托管服务曾被推荐用于部署 Expo Router 和 React 应用。然而,这种方法并不能解决处理原生应用所面临的独特挑战。以下是一些主要限制:
🌐 Historically, traditional website hosting services were recommended for deploying Expo Router and React apps. However, this approach doesn't address the unique challenges of dealing with native apps. Here are some key limitations:
- 版本同步:在应用商店发布过程中,你可能需要部署服务器的新版本。
- 请求路由复杂性:你的原生应用的不同版本可能需要路由到特定的服务器版本。这在处理请求时会增加额外的复杂性。
- 特定平台分析:运行本地应用时,你需要增强对特定平台指标的可观测性。
EAS Hosting 通过在所有平台上提供统一的部署体验来解决这些限制。
🌐 EAS Hosting addresses these limitations by providing a unified deployment experience across all platforms.
何时使用 EAS 托管
🌐 When to use EAS Hosting
| Scenario | Recommendation |
|---|---|
| Deploy a web build without setting up a separate hosting provider | |
| Use API routes or server functions in your Expo Router app | |
| Maintain consistent deployment workflows across Android, iOS, and web | |
| Automate deployments using EAS Workflows | |
| Built-in monitoring for server-side code crashes, logs, and requests | |
| Mobile-only project with no web component | |
| Full Node.js runtime compatibility (EAS Hosting uses Cloudflare Workers runtime with partial Node.js support) | |
| Already have established web infrastructure that meets your needs |
常见问题
🌐 Frequently asked questions (FAQ)
我可以在 EAS 托管中使用 API 路由吗?
EAS 托管在使用 server 输出模式时完全支持 API 路由(以 +api.ts 结尾的文件)。你可以在 EAS 仪表板 中监控 API 路由的崩溃、日志和请求情况。
🌐 EAS Hosting fully supports API routes (files ending with +api.ts) when using the server output mode. You can monitor crashes, logs, and requests from your API routes in the EAS dashboard.
EAS Hosting 使用什么运行时?
EAS Hosting 构建在 Cloudflare Workers 上,运行在 V8 JavaScript 引擎上。它使用 V8 isolates 而不是完整的 Node.js 进程。虽然提供了 Node.js 兼容模块,但存在一些限制。完整的支持模块列表请参阅 worker 运行时参考。
🌐 EAS Hosting is built on Cloudflare Workers, which runs on the V8 JavaScript engine. It uses V8 isolates instead of full Node.js processes. Node.js compatibility modules are available but with some limitations. See the worker runtime reference for the full list of supported modules.
我可以为我的生产部署设置自定义域名吗?
自定义域名 可在付费计划中使用。每个项目可以为生产部署分配一个自定义域名。支持顶层域名和子域名。
我怎样才能创建部署别名?
EAS 托管部署是不可变的。每次部署都会获得一个唯一的预览 URL。你可以创建别名来为部署分配自定义名称(例如 staging 或 production)。由于部署是不可变的,你可以通过使用 eas deploy:alias --prod --id=<deploymentId> 将别名重新分配给以前的部署 ID,从而立即回滚。
🌐 EAS Hosting deployments are immutable. Each deployment gets a unique preview URL. You can create aliases to assign custom names to deployments (such as staging or production). Since deployments are immutable, you can instantly roll back by reassigning an alias to a previous deployment ID using eas deploy:alias --prod --id=<deploymentId>.
EAS 托管提供哪些监控功能?
EAS Hosting 在 EAS 控制面板 提供内置监控功能:
🌐 EAS Hosting provides built-in monitoring in the EAS dashboard:
- 崩溃:查看来自 API 路由的未捕获错误,并按相似性分组
- 日志:来自 API 路由的所有
console.log、console.info和console.error输出 - 请求:请求元数据,包括状态、浏览器、地区和持续时间
我如何在 EAS 主机中配置缓存?
API 路由可以返回 Cache-Control 指令,EAS 托管利用这些指令在其全球 CDN(内容分发网络)上缓存响应。静态资源的默认浏览器缓存时间为 3600 秒。详情请参阅 Caching 参考。
🌐 API routes can return Cache-Control directives that EAS Hosting uses to cache responses on its global CDN (Content Delivery Network). Static assets are cached with a default browser cache time of 3600 seconds. See the Caching reference for details.
我可以在 EAS 工作流中使用 EAS 托管吗?
EAS 托管通过使用 deploy 作业类型与 EAS Workflows 集成。你可以向工作流配置中添加部署作业。例如:
🌐 EAS Hosting integrates with EAS Workflows using the deploy job type. You can add a deploy job to your workflow configuration. For example:
jobs: deploy_web: type: deploy environment: production params: prod: true
你还可以部署到特定别名,或根据分支有条件地进行生产部署:
🌐 You can also deploy to a specific alias or make production conditional based on the branch:
jobs: deploy: type: deploy params: prod: ${{ github.ref_name == 'main' }}
有关更多信息,请参阅 使用 EAS 工作流的网页部署。
🌐 For more information, see the Web deployments with EAS Workflows.
开始使用
🌐 Get started
从一个新应用到部署的网站不到一分钟。
创建别名并将部署提升到生产环境。
在你的网页和服务器代码中使用环境变量。
为你的生产部署设置自定义域。
在 EAS 托管仪表板上检查来自 API 路由的请求。
使用 EAS 工作流程自动化部署。