边缘星云

返回

部署

将你的网站部署到各种平台

包模式

本主题(v4.0.0 及以上版本)已集成 NPM 包模式。推荐的方式是移除本地包文件,从 NPM 安装主题集成。如果由于某些原因你需要修改包内容,应将本地包链接到主题模板。已集成 bun 方法,操作如下:

  1. 添加环境变量 BUN_LINK_PKG=true。
  2. 运行 bun pure check 自动链接包。

此方法也适用于其他平台(如 Vercel)的部署。只需在平台控制设置的构建选项中添加该环境变量即可。构建命令 astro-pure check && astro check && astro build 会自动链接包。

部署模式

Vercel

本主题默认支持 Vercel:

  1. 将代码推送到你的在线 Git 仓库(GitHub、GitLab、BitBucket)。
  2. 将项目导入 ↗ Vercel。
  3. Vercel 会自动检测到 Astro 并配置正确的设置。
  4. 你的应用已部署完成!(例如: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(), 
})
ts

Node 服务器

如果要在本地通过 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'] 
    }) 
  ]
})
ts

Bun 服务器

Bun 也支持静态部署方式。

查看 @nurodev/astro-bun ↗ 了解更多。

静态部署

移除 astro.config.ts 中所有服务器适配器配置:

astro.config.ts
import vercelServerless from '@astrojs/vercel/serverless'

export default defineConfig({
  //   ...
  adapter: vercelServerless(), 
  output: 'server'
})
ts

GitHub Pages

参见 Astro:为 GitHub Pages 配置 Astro ↗。

对于那些在 GitHub Pages 上部署且带有基础路径的情况(如 username.github.io/repo-name),请仔细阅读部署#带基础路径的平台。

带基础路径的平台

  1. 在 astro.config.ts 中设置 base 选项为你的基础路径,例如:

    astro.config.ts
    export default defineConfig({
      //   ...
      base: '/repo-name/' // 替换为你的仓库名称
    })
    ts
  2. 更新动态脚本文件中的所有内部链接:

    • src/components/BaseHead.astro
    • src/pages/docs/DocsContent.astro
    • src/pages/rss.xml.ts
    • packages/pure/components/pages/PostPreview.astro(需要自定义主题才能修改)
  3. 更新所有静态资源路径:

    • 在 src/site.config.ts 中添加基础路径,特别是菜单配置。
    • 在 src/plugins/shiki-transformers.ts 中为所有 /icons/code.svg 添加基础路径。
    • 在 src/assets/styles/app.css 中为 @font-face 属性中的所有 url 添加基础路径。