Inlined Tailwind classes not working for components imported from node_modules #7720
-
Here's what I've done so far:
So far I've got everything working, with the exception of inlined Tailwind classes applied to the component library's components. Here's a couple quick example components for reference... Card component using inlined styles:
Button component using a
I then package and publish the component library to NPM. Then install the package and import the components for use on my page, which looks like this: Note that any component that uses the style block + @apply (button/divider) works as expected. But my card component, which uses inline styles, does not have the expected styles applied. Out of curiosity I created a div using the same classes applied to the card:
Doing this I see the styles apply not only to this custom div, but also the card component itself. This tells me that the JIT compiler may not be "seeing" the classes embedded within the component itself, since they come from something like: I have tried adding the following to my Tailwind config, but unfortunately it did not work:
I guess the idea is Tailwind needs to know about these classes that are coming from an external source - from a NPM package in node_modules. is there a recommended way to handle this? Perhaps this is just not possible with inlined classes? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 6 replies
-
A quick follow up - I was able to get it working by setting the config content path to:
I figure I'll leave this post up just to confirm this is the best manner to solve this. Currently this requires one extra step for users consuming the library. Could I perhaps instead add this content path to the Tailwind plugin I'm already shipping bundled into the component library itself? I had added this to extend the color palette using |
Beta Was this translation helpful? Give feedback.
-
I too am dealing with this situation and have found a workaround by adding the node_module path to the |
Beta Was this translation helpful? Give feedback.
-
Thanks for confirming this is affecting you as well. I haven't had a chance to test embedding this within our plugin yet but I think that may provide a more turnkey solution for end users. However, you're right, other libraries are not having to jump through this extra hoop. I'm not sure about Headless, but I believe Smelte was still using Sapper at some point. Perhaps it's the difference between SvelteKit (which uses Vite) and Sapper (which used...snowpack? I think). |
Beta Was this translation helpful? Give feedback.
-
I can confirm Smelte is still using Sapper. The only difference I can think
of is the contributors of Smelte have set up the packaging pipeline
themselves, I am honestly not even sure if Sapper had a packaging script.
Flowbite requires its users to add the node_module to the content array as
well. Looks like a mix bag out their right now.
…On Wed, Aug 10, 2022 at 2:09 PM Chris Simmons ***@***.***> wrote:
Thanks for confirming this is affecting you as well. I haven't had a
chance to test embedding this within our plugin yet but I think that may
provide a more turnkey solution for end users. However, you're right, other
libraries are not having to jump through this extra hoop.
I'm not sure about Headless, but I believe Smelte was still using Sapper
at some point. Perhaps it's the difference between SvelteKit (which uses
Vite) and Sapper (which used...snowpack? I think).
—
Reply to this email directly, view it on GitHub
<#7720 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AG3TJVJEVVMDMNTK4USYHYDVYPV53ANCNFSM5PVROZUA>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Thats awesome! Congratulations!
…On Wed, Aug 10, 2022 at 2:33 PM Chris Simmons ***@***.***> wrote:
Hmm, interesting idea. You can check out our library here, we're fairly
far along!
https://skeleton.brainandbonesllc.com/
It's MIT licensed and open source. We launched a couple weeks ago and have
had a great response. We were even featured on the official Svelte blog for
this month's community showcase. There's two core maintainers (myself
included) and we've had a few public contributions so far. Always down for
more help if you're interested.
A couple things to note - we're about a day out from posting our first
proposed roadmap, so lots of new work to be done soon. Plus we're going to
be featured in a fairly major dev-focused news site most likely this week,
so I'm anticipating a big influx of new users soon.
—
Reply to this email directly, view it on GitHub
<#7720 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AG3TJVI5UBFG2IDQMMQ3NOLVYPYWXANCNFSM5PVROZUA>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
I think this is almost intentional since it does provide the consumer with more flexibility. I think the Tailwind/Svelte docs could improve on though is maybe having a mention of this scenario since there are so many people asking about how to do something like this. |
Beta Was this translation helpful? Give feedback.
A quick follow up - I was able to get it working by setting the config content path to:
'./node_modules/@org/packageName/**/*.{html,js,svelte,ts}'
I figure I'll leave this post up just to confirm this is the best manner to solve this. Currently this requires one extra step for users consuming the library.
Could I perhaps instead add this content path to the Tailwind plugin I'm already shipping bundled into the component library itself? I had added this to extend the color palette using
theme.extend