Skip to content

将 Astro 站点部署到 Microsoft Azure

天蓝色 是微软的云平台。你可以使用 Microsoft Azure 的 静态网络应用 服务部署 Astro 站点。

¥Azure is a cloud platform from Microsoft. You can deploy your Astro site with Microsoft Azure’s Static Web Apps service.

本指南将引导你使用 Visual Studio Code 部署存储在 GitHub 中的 Astro 站点。请参阅 Microsoft 指南,了解如何使用 Azure 管道任务 进行其他设置。

¥This guide takes you through deploying your Astro site stored in GitHub using Visual Studio Code. Please see Microsoft guides for using an Azure Pipelines Task for other setups.

¥Prerequisites

要遵循本指南,你将需要:

¥To follow this guide, you will need:

¥How to deploy

  1. Open your project in VS Code.

  2. Open the Static Web Apps extension, sign in to Azure, and click the + button to create a new Static Web App. You will be prompted to designate which subscription key to use.

  3. Follow the wizard started by the extension to give your app a name, choose a framework preset, and designate the app root (usually /) and built file location (use /dist). Astro is not listed in the built-in templates in Azure so you will need to select custom. The wizard will run and will create a GitHub Action in the .github folder of your repo. (This folder will be automatically created if it does not already exist.)

GitHub Action 将部署你的应用(你可以在 GitHub 上的存储库的 Actions 选项卡中查看其进度)。成功完成后,你可以通过单击“浏览网站”按钮(这将在 GitHub Action 运行后出现)在 SWA 扩展的进度窗口中显示的地址查看你的应用。

¥The GitHub Action will deploy your app (you can see its progress in your repo’s Actions tab on GitHub). When successfully completed, you can view your app at the address shown in the SWA Extension’s progress window by clicking the Browse Website button (this will appear after the GitHub Action has run).

¥Known Issues

为你创建的 GitHub action yaml 假定使用节点 14。这意味着 Astro 构建失败。要解决此问题,请使用此代码片段更新你的项目 package.json 文件。

¥The GitHub action yaml that is created for you assumes the use of node 14. This means the Astro build fails. To resolve this update your projects package.json file with this snippet.

"engines": {
"node": ">=18.0.0"
},

¥Official Resources

¥Community Resources

More Deployment Guides

Astro 中文网 - 粤ICP备13048890号