问题描述
我有一个关于 webpack 和提供图片的问题.
I have a question regarding webpack and serving images.
我有一个 webpack 配置,可以构建一个 React webapp,并且还提供来自特定文件夹的 .jpg 文件.
I have a webpack config that build a React webapp and also serves .jpg files from a specific folder.
但是如果我从我的 web 应用下载并添加一个新图像到这个文件夹会发生什么?
But what happens if from my webapp I download and add a new image to this folder?
我可以刷新 webpack 以便它提供新图像并且我将能够使用 require.context
导入它吗?或者,这是不是 webpack 不应该做的事情,所以我需要在后端处理这个?
Can I refresh webpack so that it will serve the new image and I will be able to import it with require.context
?Or, is it something that webpack is not supposed to do, and so I need to have this handled in the backend?
谢谢,
推荐答案
这不是 Webpack 通常会处理的事情.require.context
创建对所有模块(或在这种情况下为图像)在一个目录中,该目录可能需要与正则表达式匹配的请求,因此如果您要使用该目录,则每次从文件夹中添加或删除图像时都需要重新编译您的应用程序.
It would be best to handle this in the backend, so you can just use the URLs to the images directly.
这篇关于使用 webpack 动态提供图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!