Custom css file cannot read png and svg files
See original GitHub issue🐛 Bug Report
Webpack cannot pass PNG and SVG files when they are called inside of a CSS file
To Reproduce
(Write your steps here:)
- Create a folder src/img and add any svg file or png file
- Open your custom css files defined in the docusaurus.config.js --> presets --> @docusaurus/preset-classic --> theme --> customCss
- Add the image as background to any class
Expected behavior
The image will show up
Actual Behavior
Getting different errors for each file where webpack cannot load the filetype.
For PNG
./src/css/custom.css
ModuleParseError: Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
For SVG
./src/css/custom.css
ModuleParseError: Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <svg aria-hidden="true" data-prefix="fab" data-icon="github"
(...)
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Can't include png and svg files loaded from a CSS in the node ...
I'm using a module called React-Photoswipe, which require me to import a CSS file that contains PNGs ...
Read more >Using SVG | CSS-Tricks
SVG is an image format for vector graphics. It literally means Scalable Vector Graphics. Basically, what you work with in Adobe Illustrator.
Read more >SVG Files Showing as HTML Documents - YouTube
If your SVG files show up as "HTML Document " or "Chrome HTML Document," never fear! It's an easy fix of the settings...
Read more >5 Most Common Problems Faced by SVG Users - Vecta.io
Cannot open & edit SVG file on editors. From Illustrator to Inkscape or from Sketch to Illustrator, sometimes importing .svg files into other ......
Read more >CSS - Parcel
png resolves consistently no matter which file var(--logo) is used in. CSS modules. #. By default, CSS imported from JavaScript is global. If...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This is not provided in the config file, but you can easily do it through CSS, here is an example - https://github.com/smashgg/developer-portal/blob/master/website/static/css/custom.css#L66-L65
Try wrap the desired piece of code in
useEffecthook.The css doesn’t work since the logo configuration adds an img element and not the background of the link. With this code, I ended up with two images, one as background and one as the img element. The solution was to add the css to the link and a display none for the img.
Doing the
yarn swizzle @docusaurus/theme-classic DocPageand adding anuseEffect(addFeedbackBtn, [location.pathname]);solved my issue.Thanks for your thoughts and help. Are you all planning in added what you can
swizzlein the docs?