2

I use create-react-library cli and create component.

my component import image as follow :

import avatarImage from "../assets/avatar.png";

<img src={avatarImage} />

and when publish it to github npm pkg , and install it in project , the "node_modules>component>dist" folder has image file with name "avatar~bmRXRbfb.png".

but nothing showing in my react app ,and also "inspect" page has tag like this :

<img src="avatar~bmRXRbfb.png" >

it seems webpack work fine and bundle image correctly but address to image is not working .

update :

when import that image from component dist folder , it show image :

import image from '@component/dist/avatar~bmRXRbfb.png"

<img src={image} />

this way image path changes to media folder.

update 2:

when manually copy "avatar~bmRXRbfb.png" to public folder everything work fine !!!

Morteza Darzi
  • 33
  • 1
  • 5

0 Answers0