Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include and reference an image in react with webpack

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?

like image 398
Benvorth Avatar asked Oct 31 '22 01:10

Benvorth


1 Answers

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
like image 190
Moz Morris Avatar answered Nov 09 '22 11:11

Moz Morris