Astro Theme Pure

Back

部署

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

包模式 (Package Mode)#

本主题自 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

对于需要在具有基础路径(base path)的 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 添加基础路径。