将你的 Astro 站点部署到 Deno
你可以将服务器端渲染的 Astro 站点部署到 Deno 部署,这是一个在全球边缘运行 JavaScript、TypeScript 和 WebAssembly 的分布式系统。
¥You can deploy a server-side rendered Astro site to Deno Deploy, a distributed system that runs JavaScript, TypeScript, and WebAssembly at the edge, worldwide.
本指南包含有关通过 GitHub Actions 或 Deno Deploy 的 CLI 部署到 Deno Deploy 的说明。
¥This guide includes instructions for deploying to Deno Deploy through GitHub Actions or Deno Deploy’s CLI.
¥Requirements
本指南假设你已经安装了 Deno。
¥This guide assumes you already have Deno installed.
¥Project Configuration
此页面提供将你的 Astro 项目作为服务器端渲染站点 (SSR) 部署到 Deno 部署 的说明。
¥This page provides instructions for deploying your Astro project to Deno Deploy as a server-side rendered site (SSR).
要部署静态站点,请参阅 Deno 部署静态站点教程。
¥To deploy a static site, see the Deno deploy static site tutorial.
SSR 适配器
Section titled SSR 适配器¥Adapter for SSR
要在 Astro 项目中启用 SSR 并部署在 Deno Deploy 上:
¥To enable SSR in your Astro project and deploy on Deno Deploy:
使用以下 astro add
命令添加 Deno 适配器 以在 Astro 项目中启用 SSR。这将一步安装适配器并对 astro.config.mjs
文件进行适当的更改。
¥Add the Deno adapter to enable SSR in your Astro project with the following astro add
command. This will install the adapter and make the appropriate changes to your astro.config.mjs
file in one step.
如果你更愿意手动安装适配器,请完成以下两个步骤:
¥If you prefer to install the adapter manually instead, complete the following two steps:
-
Install the
@deno/astro-adapter
adapter to your project’s dependencies using your preferred package manager. If you’re using npm or aren’t sure, run this in the terminal: -
Update your
astro.config.mjs
project configuration file with the changes below.Next, Update your
preview
script inpackage.json
with the change below.You can now use this command to preview your production Astro site locally with Deno.
如何部署 SSR Astro 站点
Section titled 如何部署 SSR Astro 站点¥How to deploy an SSR Astro site
你可以通过 GitHub Actions 或使用 Deno Deploy 的 CLI(命令行接口)部署到 Deno Deploy。
¥You can deploy to Deno Deploy through GitHub Actions or using Deno Deploy’s CLI (command line interface).
GitHub Actions 部署
Section titled GitHub Actions 部署¥GitHub Actions Deployment
如果你的项目存储在 GitHub 上,Deno 部署网站 将指导你设置 GitHub Actions 来部署你的 Astro 站点。
¥If your project is stored on GitHub, the Deno Deploy website will guide you through setting up GitHub Actions to deploy your Astro site.
-
Push your code to a public or private GitHub repository.
-
Sign in on Deno Deploy with your GitHub account, and click on New Project.
-
Select your repository, the branch you want to deploy from, and select GitHub Action mode. (Your Astro site requires a build step, and cannot use Automatic mode.)
-
In your Astro project, create a new file at
.github/workflows/deploy.yml
and paste in the YAML below. This is similar to the YAML given by Deno Deploy, with the additional steps needed for your Astro site. -
After committing this YAML file, and pushing to GitHub on your configured deploy branch, the deploy should begin automatically!
You can track the progress using the “Actions” tab on your GitHub repository page, or on Deno Deploy.
CLI 部署
Section titled CLI 部署¥CLI Deployment
-
Install the Deno Deploy CLI.
-
Run your Astro build step.
-
Run
deployctl
to deploy!In the command below, replace
<ACCESS-TOKEN>
with your Personal Access Token and<MY-DENO-PROJECT>
with your Deno Deploy project name.You can track all your deploys on Deno Deploy.
-
(Optional) To simplify the build and deploy into one command, add a
deploy-deno
script inpackage.json
.Then you can use this command to build and deploy your Astro site in one step.