部署你的 Astro 站点
准备好构建和部署你的 Astro 网站了吗?请遵循我们针对不同部署服务的指南之一,或向下滚动以获取有关部署 Astro 站点的一般指南。
¥Ready to build and deploy your Astro site? Follow one of our guides to different deployment services or scroll down for general guidance about deploying an Astro site.
¥Deployment Guides
快速部署选项
Section titled 快速部署选项¥Quick Deploy Options
你可以使用网站的仪表板 UI 或 CLI 快速构建 Astro 站点并将其部署到多个主机。
¥You can build and deploy an Astro site to a number of hosts quickly using either their website’s dashboard UI or a CLI.
网站用户界面
Section titled 网站用户界面¥Website UI
部署网站的一种快速方法是将 Astro 项目的在线 Git 存储库(例如 GitHub、GitLab、Bitbucket)连接到主机提供商,并利用 Git 进行持续部署。
¥A quick way to deploy your website is to connect your Astro project’s online Git repository (e.g. GitHub, GitLab, Bitbucket) to a host provider and take advantage of continuous deployment using Git.
这些主机平台会自动检测对 Astro 项目源存储库的推送,构建你的站点并将其部署到自定义 URL 或你的个人域的网络上。通常,在这些平台上设置部署将遵循如下步骤:
¥These host platforms automatically detect pushes to your Astro project’s source repository, build your site and deploy it to the web at a custom URL or your personal domain. Often, setting up a deployment on these platforms will follow steps something like the following:
-
Add your repository to an online Git provider (e.g. in GitHub, GitLab, Bitbucket)
-
Choose a host that supports continuous deployment (e.g. Netlify or Vercel) and import your Git repository as a new site/project.
Many common hosts will recognize your project as an Astro site, and should choose the appropriate configuration settings to build and deploy your site as shown below. (If not, these settings can be changed.)
-
Click “Deploy” and your new website will be created at a unique URL for that host (e.g.
new-astro-site.netlify.app
).
主机将自动配置为监视 Git 提供商的主分支的更改,并在每次新提交时重建和重新发布你的站点。这些设置通常可以在主机提供商的仪表板 UI 中进行配置。
¥The host will be automatically configured to watch your Git provider’s main branch for changes, and to rebuild and republish your site at each new commit. These settings can typically be configured in your host provider’s dashboard UI.
CLI 部署
Section titled CLI 部署¥CLI Deployment
有些主机有自己的命令行接口 (CLI),你可以使用 npm 将其全局安装到你的计算机上。通常,使用 CLI 进行部署如下所示:
¥Some hosts will have their own command line interface (CLI) you can install globally to your machine using npm. Often, using a CLI to deploy looks something like the following:
-
Install your host’s CLI globally, for example:
-
Run the CLI and follow any instructions for authorization, setup etc.
-
Build your site and deploy to your host
Many common hosts will build and deploy your site for you. They will usually recognize your project as an Astro site, and should choose the appropriate configuration settings to build and deploy as shown below. (If not, these settings can be changed.)
Other hosts will require you to build your site locally and deploy using the command line.
在本地构建你的网站
Section titled 在本地构建你的网站¥Building Your Site Locally
Netlify 和 Vercel 等许多主机将为你构建站点,然后将该构建输出发布到网络上。但是,某些站点将要求你在本地构建,然后运行部署命令或上传构建输出。
¥Many hosts like Netlify and Vercel will build your site for you and then publish that build output to the web. But, some sites will require you to build locally and then run a deploy command or upload your build output.
你可能还希望在本地构建以预览你的站点,或捕获你自己的环境中的任何潜在错误和警告。
¥You may also wish to build locally to preview your site, or to catch any potential errors and warnings in your own environment.
运行命令 npm run build
来构建你的 Astro 站点。
¥Run the command npm run build
to build your Astro site.
默认情况下,构建输出将放置在 dist/
处。可以使用 outDir
配置选项 更改此位置。
¥By default, the build output will be placed at dist/
. This location can be changed using the outDir
configuration option.
为 SSR 添加适配器
Section titled 为 SSR 添加适配器¥Adding an Adapter for SSR
Recipes