Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inlining of SVG icons used in CSS (in examples like examples/react-rich/) #7236

Open
vadimkantorov opened this issue Feb 22, 2025 · 1 comment

Comments

@vadimkantorov
Copy link

vadimkantorov commented Feb 22, 2025

In Lexical examples (e.g. in https://github.com/facebook/lexical/blob/main/examples/react-rich/src/styles.css), SVG icons are used like so: i.undo { background-image: url(icons/arrow-counterclockwise.svg); }

It appears that it should prevent SVG asset inlining feature in Vite:

  • docs(assets): add note to inlining SVG through url() vitejs/vite#15534 - double-quotes seem needed url("icons/arrow-counterclockwise.svg") by Vite to parse these usages in CSS
  • what could also prevent inlining: vite currently produces warnings like icons/arrow-counterclockwise.svg referenced in icons/arrow-counterclockwise.svg didn't resolve at build time, it will remain unchanged to be resolved at runtime

Currently the ./public/icons/ directory currently gets copied to ./dist/icons/ (despite all my attempts to make them inline with https://github.com/facebook/lexical/blob/main/examples/react-rich/ as example)

@vadimkantorov
Copy link
Author

vadimkantorov commented Feb 25, 2025

What worked for inlining the SVG icons into CSS using the built-in Vite SVG inlining:

  • moving public/icons/ to assets/icons/
  • replacing url(icons/...) with url("../assets/icons/...")

I think, for toolbar icons inlining makes sense (especially for examples), so maybe worth at least mentioning this in README of examples/react-rich (and other examples) or actually move away from special public dir for toolbar SVG icons

@vadimkantorov vadimkantorov changed the title Inlining of SVG icons used in CSS Inlining of SVG icons used in CSS (in examples like examples/react-rich/) Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant