Answer the question
In order to leave comments, you need to log in
How to add before for react component in css?
I import the Css file into the component, I placed the picture in public, it is higher in the hierarchy by several folders. I read somewhere that you just need to specify the file name in content:"" , but then the error Error: Module not found: Can't resolve './maps-location.jpg'
Answer the question
In order to leave comments, you need to log in
You can put the image in the same folder as the CSS file. Then it will be possible to do this in the CSSnik url('./image.jpg')
, and the webpack will destroy this matter during compilation and place the image where it needs to be.
If you came to React and modular bundlers (aka Webpack) from the good old Galp or did without it before, then this approach breaks the stereotype a bit. We are used to storing pictures in a folder public/images
and styles in a folder public/styles
. But in the world of webpack, it's perfectly normal to keep styles and statics next to your code. Actually, webpack is needed in order to connect and distribute it as needed.
Recently, the approach of the so-called Modular CSS (CSSModules) has become popular: this is when the styles and static files related to the component are stored in the component folder. Webpack itself will take care of putting styles and statics where necessary during compilation. For this we love him.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question