qwik: Pure qwik app/library: CSS from library doesn't load in the app by default
Qwik Version
0.0.39
Operating System (or Browser)
windows
Node Version (if applicable)
No response
Which component is affected?
Qwik Rollup / Vite plugin
Expected Behaviour
- Create a component library from starter and add a component which imports styles in module.css.
- Build the component library to produce the
/lib/
folder content. This produces a concatenated .css file. - Create a qwik app and npm link to the library. Add the component to your page.
Expected: Component renders and is styled.
Actual Behaviour
Component renders and is missing styling. It is ok if there is a manual step here as long as it’s documented somewhere, but I’m not sure what the strategy currently is. Either it should just work, or there should be some docs here.
I also want to suggest: concatenating the css at the library layer seems less ideal. If I export 20 components and the consumer uses 3 of them, I’d prefer to only have 3 modules worth of styling processed.
A better approach perhaps: let the library emit extractable but functional intermediate output so that optimization can happen later. Make the app build extract the module css referenced in the build graph and do this work once we understand the bundle output.
This essentially is what we are working on here: https://github.com/microsoft/griffel (runtime injectable css but extractable at app build time.) Similar to stylex from facebook or Linaria.
Additional Information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 21 (10 by maintainers)
Commits related to this issue
- fix: 💄 add default css styles to toaster component BuilderIO/qwik#948 — committed to diecodev/qwik-sonner by diecodev 6 months ago
Hmm, there’s a couple of moving parts here.
filename.qwik.js
. So not the source files but the built library files.css
import will be added to the global CSS file. I’m not sure if this also happens for imports under node_modules, probably not.useStyles$
, which can be used inside of imported modules, provided they are named*.qwik.js
So, if you want to magically provide CSS for your user, your components should use
useStyles$
. Otherwise, you provide a.css
file for them to import, and they can decide whether to useuseStyles$
or add to their global .css themselves.PS: Here it tests for .qwik.js https://github.com/BuilderIO/qwik/blob/270a7beaf9efd733849af946ab14eb15c8e7362d/packages/qwik/src/optimizer/src/plugins/plugin.ts#L564 - needed because library files can’t have a .tsx extension
Lib mode is completely broken. Does anyone have any workaround for this issue?