UI Developer
UI Developer

Reputation: 29

Unable to access images from public folder with webpack configuration

I want to use images using url not by using import statement.

Expected way: <img src={"/images/logo.png"} alt="logo" className={classes.logo} />

Not Expected: import logo from '../../../public/images/logo.png'

following is my application structure, Please let me know what loader or configuration or any better way is present for dev & prod environment?

ss

Here is my webpack configuration for development.

ss2

Thanks in advance :)

Upvotes: 1

Views: 878

Answers (1)

Agent 047
Agent 047

Reputation: 98

Try this

 <img src={process.env.PUBLIC_URL + '/yourPath.jpg'} /> 

Or this should also work

<img src={window.location.origin + '/yourPath.jpg'} />

Upvotes: 0

Related Questions