solid-lib-starter icon indicating copy to clipboard operation
solid-lib-starter copied to clipboard

How can I use css modules in the src?

Open xypnox opened this issue 1 year ago • 5 comments

Describe the bug

I want to make a library of a preset components with styles. However, adding a styles.module.css and importing it doesn't seem to work.

Ref:

https://github.com/xypnox/xip-solidjs-test https://github.com/xypnox/xip-solidjs-test/tree/main/src/buttons

Minimal Reproduction Link

https://stackblitz.com/~/github.com/xypnox/xip-solidjs-test

xypnox avatar Mar 04 '24 15:03 xypnox

Does esbuild support css modules ootb? Maybe you need to use something like this: https://www.npmjs.com/package/esbuild-css-modules-plugin

thetarnav avatar Mar 04 '24 16:03 thetarnav

Ok it actually does https://esbuild.github.io/content-types/#css-from-js

thetarnav avatar Mar 04 '24 16:03 thetarnav

Looking at the esbuild's docs I couldn't find a clear config or the reason why css module files are not being detected correctly.

Are there any suggestions where I should look for this?

I tried using postcss as described in tsup to support css. Ref: https://github.com/xypnox/xip-solidjs-test/tree/use-postcss

The css files gets generated in the dist but the user of the library has to import the css files from node modules/package specifically. Ideally it should be auto-imported depending on whether the component was used or not.

Moreover the postcss plugin is also affecting the css in dev.

xypnox avatar Mar 05 '24 15:03 xypnox

The css files gets generated in the dist but the user of the library has to import the css files from node modules/package specifically. Ideally it should be auto-imported depending on whether the component was used or not.

this is expected tsup/esbuild can only bundle and copy the imported css to dist it won’t do any magic for the user

thetarnav avatar Apr 08 '24 14:04 thetarnav