Include and reference an image in react with webpack
Asked Answered
V

1

6

What ist the best way to include and reference images for react-usage in a singlepage JavaScript app build and bundled with webpack?

So far i have

return (<img src={require('./pic.png'}</div>)

Is there a better way?

Virelay answered 20/6, 2015 at 9:51 Comment(1)
Depending on the situation, sometimes a spritesheet makes more sense.Yawata
P
3

If you're using Webpack's url-loader you can tell it to automatically embed a data uri if the file size is under a specified limit.

require("url?limit=10000!./pic.png");
// => DataUrl if "pic.png" is smaller that 10kb
Pocketful answered 20/6, 2015 at 14:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.