部署
将您的网站部署到各种平台
包模式 (Package Mode)#
本主题自 v4.0.0 版本起集成了 NPM 包模式。推荐的方式是移除本地包文件,并从 NPM 安装主题集成。如果由于某些原因您想修改包内容,则应将本地包链接到您的主题模板。主题已集成 bun 方法,您需要:
- 添加环境变量
BUN_LINK_PKG=true。 - 运行
bun pure check自动链接包。
此方法也适用于部署到其他平台(如 Vercel)。您只需在平台的构建选项设置中添加该环境变量即可。构建命令 astro-pure check && astro check && astro build 将会自动链接包。
部署模式#
Vercel#
本主题默认支持 Vercel:
- 将代码推送到您的在线 Git 仓库(GitHub, GitLab, BitBucket)。
- 将 项目导入 ↗ Vercel。
- Vercel 将自动检测 Astro 并配置正确的设置。
- 您的应用程序已部署!(例如:astro.vercel.app ↗)
Vercel 也支持静态方法:
astro.config.ts
import vercelServerless from '@astrojs/vercel/serverless'
import vercelStatic from '@astrojs/vercel/static';
export default defineConfig({
// ...
adapter: vercelServerless()
adapter: vercelStatic(),
})tsNode 服务器#
如果您是在本地使用 Node.js 部署,首先需要安装 @astrojs/node:
bun add '@astrojs/node'shell然后按照 astro.config.ts 中的注释进行如下修改:
astro.config.ts
import node from '@astrojs/node'
import vercelServerless from '@astrojs/vercel/serverless'
export default defineConfig({
// ...
adapter: vercelServerless(),
adapter: node({ mode: 'standalone' }),
integrations: [
// prettier-ignore
outputCopier({
integ: ['sitemap', 'pagefind']
})
]
})tsBun 服务器#
Bun 也支持静态方法。
查看 @nurodev/astro-bun ↗ 了解更多信息。
静态部署#
移除 astro.config.ts 中所有的服务器适配器配置:
astro.config.ts
import vercelServerless from '@astrojs/vercel/serverless'
export default defineConfig({
// ...
adapter: vercelServerless(),
output: 'server'
})tsGitHub Pages#
参见 Astro: 为 GitHub Pages 配置 Astro ↗。
对于需要在具有基础路径(base path)的 GitHub Pages 上部署的用户(例如 username.github.io/repo-name),请仔细阅读 部署#具有基础路径的平台。
具有基础路径的平台#
-
在
astro.config.ts中将base选项设置为您的基础路径,例如:astro.config.ts
tsexport default defineConfig({ // ... base: '/repo-name/' // 替换为您的仓库名称 }) -
更新动态脚本文件中的所有内部链接:
src/components/BaseHead.astrosrc/pages/docs/DocsContent.astrosrc/pages/rss.xml.tspackages/pure/components/pages/PostPreview.astro(需要 自定义主题 才能进行更改)
-
更新所有静态资源路径:
- 在
src/site.config.ts中添加基础路径。特别是菜单配置。 - 在
src/plugins/shiki-transformers.ts中为所有的/icons/code.svg添加基础路径。 - 在
src/assets/styles/app.css中为@font-face属性中的所有 URL 添加基础路径。
- 在