question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:)

  1. Create a folder src/img and add any svg file or png file
  2. Open your custom css files defined in the docusaurus.config.js --> presets --> @docusaurus/preset-classic --> theme --> customCss
  3. 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:closed
  • Created 4 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
lex111commented, Jan 27, 2020

1 - Is there a way in the config.js to select a different logo for when the website is dark? Or should I do it in the CSS?

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

For v1, I had a custom script for the window.addEventListener(“load”, doSomething)…

Try wrap the desired piece of code in useEffect hook.

0reactions
prma85commented, Jan 28, 2020

1 - Is there a way in the config.js to select a different logo for when the website is dark? Or should I do it in the CSS?

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

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.

You can to swizzle the DocPage component and put the necessary script there. @yangshun although there may be another option?

Doing the yarn swizzle @docusaurus/theme-classic DocPage and adding an useEffect(addFeedbackBtn, [location.pathname]); solved my issue.

Thanks for your thoughts and help. Are you all planning in added what you can swizzle in the docs?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found