Skip to content

将你的 Astro 站点部署到 Azion

你可以在 Azion 上部署 Astro 项目,Azion 是前端开发者协作和部署静态 (JAMstack) 和 SSR 网站的平台。

¥You can deploy your Astro project on Azion, a platform for frontend developers to collaborate and deploy static (JAMstack) and SSR websites.

¥Prerequisites

首先,你将需要:

¥To get started, you will need:

  • Azion 账户。如果你没有,可以注册一个免费账户。

  • 你的应用代码存储在 GitHub 存储库中。

  • 安装 Azion CLI 以加快项目设置和部署。

如何通过 Azion 控制台仪表板进行部署

标题部分 如何通过 Azion 控制台仪表板进行部署

¥How to Deploy through Azion Console Dashboard

要开始构建,请按照以下步骤操作:

¥To start building, follow these steps:

  1. Access Azion Console.
  2. On the homepage, click the + Create button.
    • This opens a modal with the options to create new applications and resources.
  3. Select the Import from GitHub option and click the card.
    • This action opens the settings page.
  4. Connect your Azion account with GitHub.
    • A pop-up window will appear asking for authorization.
  5. Select the repository you want to import from GitHub.
  6. Configure the build settings:
    • Framework preset: Select the appropriate framework (e.g., Astro).
    • Root Directory: This refers to the directory in which your code is located. Your code must be located at the root directory, not a subdirectory. A ./ symbol appears in this field, indicating it’s a root directory.
    • Install Command: the command that compiles your settings to build for production. Build commands are executed through scripts. For example: npm run build or npm install for an NPM package.
  7. Click Save and Deploy.
  8. Monitor the deployment using Azion Real-Time Metrics and verify your site is live on the edge.

如何使用 Azion CLI 部署静态站点

标题部分 如何使用 Azion CLI 部署静态站点

¥How to Deploy a Static Site Using the Azion CLI

  1. Install the Azion CLI:

    • Download and install the Azion CLI for easier management and deployment.
  2. Authenticate the CLI:

    • Run the following command to authenticate your CLI with your Azion account.
    终端窗口
    azion login
  3. Set Up Your Application:

    • Use the following commands to initialize and configure your project:
    终端窗口
    azion init
  4. Build Your Astro Project:

    • Run your build command locally:
    终端窗口
    azion build
  5. Deploy Your Static Files:

    • Deploy your static files using the Azion CLI:
    终端窗口
    azion deploy

本指南概述了部署静态应用。

¥This guide provides an overview of deploying static applications.

使用 Azion CLI 启用本地开发

标题部分 使用 Azion CLI 启用本地开发

¥Enabling Local Devlopment Using Azion CLI

要使预览正常工作,你必须执行以下命令:

¥For the preview to work, you must execute the following command:

终端窗口
azion dev

初始化本地开发服务器后,应用将经历 build 过程。

¥Once you’ve initialized the local development server, the application goes through the build process.

终端窗口
Building your Edge Application. This process may take a few minutes
Running build step command:
...

然后,构建完成后,将提示访问应用:

¥Then, when the build is complete, the access to the application is prompted:

终端窗口
[Azion Bundler] [Server] › ✔ success Function running on port http://localhost:3000

¥Troubleshooting

¥Node.js runtime APIs

使用 NPM 包的项目无法构建,并显示错误消息,例如 [Error] Could not resolve "XXXX. The package "XXXX" wasn't found on the file system but is built into node.

¥A project using an NPM package fails to build with an error message such as [Error] Could not resolve "XXXX. The package "XXXX" wasn't found on the file system but is built into node.:

这意味着你使用的包或导入与 Azion 的运行时 API 不兼容。

¥This means that a package or import you are using is not compatible with Azion’s runtime APIs.

如果你直接导入 Node.js 运行时 API,请参阅 Azion Node.js 兼容性 以了解如何解决此问题的进一步步骤。

¥If you are directly importing a Node.js runtime API, please refer to the Azion Node.js compatibility for further steps on how to resolve this.

如果你导入的包会导入 Node.js 运行时 API,请与包的作者核实他们是否支持 node:* 导入语法。如果没有,你可能需要寻找替代包。

¥If you are importing a package that imports a Node.js runtime API, check with the author of the package to see if they support the node:* import syntax. If they do not, you may need to find an alternative package.

更多部署指南

Astro 中文网 - 粤ICP备13048890号