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

如何在AstroJS执行构建时将远程图片保存到本地构建产物中?

问题

我有如下AppImage.astro组件:

---
import { Image } from 'astro:assets';
---
<Image src="https://example.com/remote-bird.jpg" alt="A bird." inferSize />

现在希望在生成构建产物时,将这张远程图片保存到构建目录中,并从该目录提供图片服务。

解决方案

在Astro配置文件中添加远程图片域名的允许规则:

export default defineConfig({
    image: {
        remotePatterns: [{
            protocol: 'https',
            hostname: 'example.com', // 你的图片源域名
          }],
    }
});

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 14:12:03