-
Notifications
You must be signed in to change notification settings - Fork 361
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
CSS module contents not being inlined #813
Comments
Do I need to add more context/info here? I see more recent issues being addressed and I'm still stuck here with no replies. |
The To illustrate: style.css
index.js
With index.js
CSS Modules you generate hashed class names, but keep the CSS files around. You then use the hashes in the class attribute in your markup. Really different uses. People respond to issues when they can, it's not necessarily anything wrong with your issue if no one responds. There's a lot of repositories and only so many hours in the day. |
Thank you very much for the answer, @rschristian I'll try and remove the inline flag. On the other hand, when I try to consume this components on NextJS I get an error that the bundle should contain the CSS inside the same file as the JS. Is there any way to concat it? |
@dowrow Nothing to apologize for, you weren't being pushy. Just an honest question. What do you mean by "the bundle should contain the CSS inside the same file as the JS"? I can't imagine they're actually advocating for nothing but inline styles, but I've never used Next. Can you show this error? Is there a way to concat what? CSS Modules need to either have the styles in a If you just want to use inline styles you certainly can do that, something like |
If you did end up wanting to not require your users import a style sheet, |
Sure, this is the output I get when building the Next webapp:
Following that link, you can read:
So yes, I guess they are advocating for inlining styles or requiring the users to import the stylesheets separately. I see how react-colorful worked around this restriction. I was just looking for an easy solution that somehow transformed my 37 components (all of which use CSS modules) into components with inlined styles, but looks like I had no luck! Thank you a lot anyway, @rschristian |
Edit: Misread. How does your lib have any reference to a CSS file? Microbundle strips those? Are you adding a CSS import (i.e.,
Yeah, |
Good question, I guess had some old dist files from an earlier build with Parcel that required the css files.
I see. Problem is Next doesn't allow me to import any .css except for CSS modules outside the _app. So, basically I have no way to create self-contained components for Next using Microbundle :s |
The error message is that you're importing a CSS file in built JS. It might not resolve all the problems but does need to be fixed, then other errors will appear, if any, and you can fix those. Next doesn't seem to allow any CSS imports from Still, is there any reason why you can't import your style sheets into Not really a Microbundle limitation/issue but a NextJS one (as seen by the amount of people begging for that functionality). |
Yes, I meant I can't just stripe the CSS imports if there's no any other way to import the styles later on.
Sure, for anyone else interested there's this thread about the topic: vercel/next.js#13282 CSS-in-JS styles (aka <style jsx>{``}</style>) would result on styles being defined inside the dist/index.js, right? This might be my best bet for what I want to accomplish. I wonder if there's any other way to transform the styles defined on the CSS modules to CSS-in-JS.
I guess I could import the generated dist/index.css of each component on the _app.js and it should work, but feels hacky and polluted to include 37 global stylesheets. Again, thank you for your time, @rschristian |
Hello, I'm using microbundle to build a library mono-repo.
I'm using lerna and yarn workspaces.
Also, my components use React (.js only no TS) and CSS modules.
The package.json of a sample package looks like this:
And my root package.json:
yarn build works and bundles with no error, but for some reason the styles defined in the Accordion.module.css (which are imported straight from the Accordion.js) are not being copied into the dist files.
Am I missing something?
The text was updated successfully, but these errors were encountered: