如何将用于生产的图像从资产复制到 public/assets

How to copy images for production from assets to public/assets

我使用的是 Gatsby + Strpai,我遇到了插入到正文内容中的图像的问题。

为了呈现我正在使用 ReactMarkdown 的内容和在开发和生产中找不到的图像,我通过用资产替换路径上传解决了这个问题。

<ReactMarkdown transformImageUri={(uri) => uri.startsWith('http') ? uri : `${process.env.BASE_URL}${uri.replace('uploads', 'static')}` }>
  {content}
</ReactMarkdown>

但在生产模式下,图像仍然不可用,因为它们没有在构建时复制到 public/static 文件夹。

另一种解决方法是在项目的根目录下创建一个静态文件夹并将图像放在那里,但它们会被复制到 public/ 而不是我希望它们在 public/static 中可用

我有什么办法可以做到这一点,或者您对此类问题有其他建议吗?

除此之外,对我来说这似乎是 Strapi source plugin(或其他 Gatsby 插件)的错误配置,因为图像应该在开发或构建中都可用(它们应该复制到本地以允许 Gatsby 创建可查询图像节点)。

所有由任何组件处理的解决方案对我来说似乎是一个矫枉过正的解决方案,一个无法解决问题根源的补丁(图像未正确下载到本地)。

Another workaround for this was to create a static folder at the root of the project and put images there, but they are copied to the public/ instead I want them to be available in public/static

如果这是适合您的用例的解决方案,您可以创建一个 /static/static 文件夹结构(在项目的根目录中),在项目构建时将其转换为 /public/static