问题
I have a question regarding webpack and serving images.
I have a webpack config that build a React webapp and also serves .jpg files from a specific folder.
But what happens if from my webapp I download and add a new image to this folder?
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?
Thanks,
回答1:
This isn't something that would typically be handled by Webpack. require.context
creates references to all modules (or in this case images) in a directory that can be required with a request matching a regular expression, so if you were to use that, you'd need to recompile your app every time you add or remove an image from the folder.
It would be best to handle this in the backend, so you can just use the URLs to the images directly.
来源:https://stackoverflow.com/questions/46889634/serve-images-dynamically-with-webpack