You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Astro.js部署至GitHub Pages:媒体文件无法渲染

Astro.js 部署GitHub Pages后媒体文件无法渲染问题解决记录
  • 近期尝试用Astro.js构建首个作品集并部署至GitHub Pages,开发模式下所有内容显示正常,构建过程也无报错,但部署后页面里的SVG图片和MP4背景视频均无法正常渲染,媒体文件是通过<img>和<video>标签引入的。
  • 部署时直接照搬了Astro官方文档提供的GitHub Actions配置文件.github/workflows/main.yaml,配置代码如下:
name: Deploy Astro to GitHub Pages

on:
  # Trigger the workflow every time you push to the `main` branch
  # Using a different branch name? Replace `main` with your branch’s name
  push:
    branches: [ main ]
  # Allows you to run this workflow manually from the Actions tab on GitHub.
  workflow_dispatch:

# Allow this job to clone the repo and create a page deployment
permissions:
  contents: read
  pages: write
  id-token: write

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout your repository using git
        uses: actions/checkout@v2          
      - name: Install, build, and upload your site
        uses: withastro/action@v0
        with:
            # path: . # The root location of your Astro project inside the repository. (optional)
            # node-version: 16 # The specific version of Node that should be used to build your site. Defaults to 16. (optional)
          package-manager: npm # The Node package manager that should be used to install dependencies and build your site. Automatically detected based on your lockfile. (optional)


  deploy:
    needs: build
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v1
  • 后续补充:因未仔细阅读Astro官方文档的提示警告,导致出现此问题,现已按照文档提示解决。

内容的提问来源于stack exchange,提问作者pedro correia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 02:31:31