Load local images in React.js

后端 未结 10 2098
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 23:08

I have installed React using create-react-app. It installed fine, but I am trying to load an image in one of my components (Header.js, file path: <

10条回答
  •  醉话见心
    2020-11-30 23:29

    Best approach is to import image in js file and use it. Adding images in public folder have some downside:

    • Files inside public folder not get minified or post-processed,

    • You can't use hashed name (need to set in webpack config) for images , if you do then you have to change names again and again,

    • Can't find files at runtime (compilation), result in 404 error at client side.

提交回复
热议问题