Hi my app running good at localhost but when I create build then Background image not displaying.
my code is.
<div style={{ backgroundImage:"url("+require("assets/img/bg.jpg")+")", height: "400px",
backgroundSize: "cover",
backgroundPosition: "center top"}}>
But at live server empty header with path
When I inspect this path then showing like this.
background-image: url(./static/media/bg6.488bc24….jpg);
Please help with thanks
3
Answers
You can try importing the image outside of the function instead of requiring it.
PS:- You can kindly attach a SS of your build folder for further info.
Perhaps, upon build, programmatically defined path is being changed or appoints to an undesired resource.
You could try to modify your DOM and apply css, by adding a dedicated tag, like so:
Put your file to public folder and replace require with string with path.
For example put file to public/assets/img/bg.jpg
And change path:
or you can use import and put imported image to img (src prop).