Inline styles from css-modules in bundle #18780
-
I have a requirement to build a single all-in-one js file, including both code and styles of my app. I know that Vite has an option of importing css files like Same can be done with css-modules – but since they produce their own export, an object with generated classnames – using
Is there an option or maybe plugin to have both at once? same question on SO, unanswered for a while |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I second that. When you are working with a large codebase, it is often necessary to make small adjustments to components styled using global/shared modules. That typically involves writing one or two rules, often re-using class names from imported modules. It works, except that there is now a 50 byte CSS file that needs to be managed separately from JS file with the component code. It would be great if small (below threshold) CSS could be inlined into component code and appended to when imported. There is, however, a risk of class name collisions as any components that |
Beta Was this translation helpful? Give feedback.
-
Found it: https://github.com/marco-prontera/vite-plugin-css-injected-by-js @thexeos your specific need of having an inlining threshold isn't supported by this plugin. |
Beta Was this translation helpful? Give feedback.
Found it: https://github.com/marco-prontera/vite-plugin-css-injected-by-js
This plugin solved all my needs.
@thexeos your specific need of having an inlining threshold isn't supported by this plugin.
As I understand, it operates on the resulting Vite's output, not on particular source files. So if Vite decided to concat all your css in one file, there is nothing to do about it.
If you know the way to address this behavior, then maybe this option can help you.