You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ah yes, the dreaded first issue! Fortunately more of a question/discussion point than anything.
Is there a best way to use Tailwind with Vue single file components? It would be really nice to keep those one-off styles or component styles inside Vue components themselves, but the tricky part is getting component CSS between the preflight and utilities lines.
The only thing I can think of is to have 2 files — The first file would just contain @tailwind preflight;, and the second would have @tailwind utilities; + any custom utilities users want. In Laravel Mix, if we use the extractVueStyles option, that should extract the Vue component styles at the top of the second file, which is what we want. We could then use Mix's combine() function to join 'em together.
Last I suppose we'd have to add Tailwind to vue-loader's PostCSS options.
Nevermind, all PostCSS plugins in Mix apply to Vue component styles as well, no need to do it manually. 👍
I haven't had a chance to actually test this approach but I figured I'd gather some thoughts in case there's a better way.
Edit Again: Ok! I tested the above approach and it seems to work great. My Vue styles get injected in the right spot, and I'm also able to successfully use Tailwind functions (config, @apply, etc) inside my Vue components. 🎉
Reacted by Simon, Edwin Ramírez, Elliott Minns, Diky Arga, Tony and Husam Elbashir
Reacted by Michał Karnicki, Lanny Bose and Husam Elbashir
Can you show me your mix setup? I'm struggling with setting it up the way you suggested. My extracted Vue styles are just being inserted in between the output of preflight and utilities, but they're not being processed by PostCSS.
Reacted by Emmanuel Hadoux, Lanny Bose, Michał Karnicki and Daniel Ramirez
@syropian and @reinink, I'm hitting the same wall as @unxsist... Keep getting unable to find .bg-blue when trying to @apply in me Vue component... What's the mix config that could get me home here?
@unxsist@lperiodbose Unfortunately you have to include @tailwind utilities; in your style block. The very unfortunate side effect being this duplicates all of Tailwind into the output and your CSS file will row exponentially. More on this issue can be found here: #150
Reacted by Lanny Bose, Devin Norgarb and Andrei Scripcaru
So I can think of a few ways that we could make it possible to @apply classes that aren't defined in the same scope:
Add some sort of @silent { ... } at-rule for generating the utilities so they are available when @apply runs but stripped by the time Tailwind is totally finished:
Make Tailwind always fallback to looking for a matching utility in the utilities it would generate, even if they haven't been generated into the current scope. So @apply .bg-red would work as long as Tailwind would generate that utility if you did add @tailwind utilities to that file.
The only thing I dislike about this approach is it doesn't let you use @apply for custom utilities that aren't generated by Tailwind like you can normally.
I'm somewhat hesitant to solve this problem because I really don't want to encourage people to start using Tailwind solely as a library for building component classes, but if it's really a big problem for people then maybe we can try something.
Reacted by Collin Henderson, Michaël De Boey, Jeroen Nijhuis, Sean Kegel, Brian Kimball, James Harris, Gregory Guepy, Andrei Scripcaru and Ivan Vilanculo
Is there a solution for this that Vue users not using Mix could implement? It looks like @silent is not implemented. I'm just setting up tailwind in a large Vue project, and I honestly don't know yet how I'll need/want to compose with @apply, but it's advertised in the documentation by virtue of the Extracting Components section. Usage in a single file component environment shouldn't preclude me from being able to compose things in that environment, right? Especially if I'm going to use tailwind as the primary source of truth for a color palette. Possibly confusing my setup is the fact that SCSS is already implemented, so style blocks in vue are using that lang attribute.
Update
Looks like the failures to compile the @apply rules were breaking the color config usage. Color config works fine once all errors are fixed.
Thanks @r0skar, I updated my comment when I figured out that the broken @apply was also breakingconfig(). That's working now that I've removed all my attempts at @apply.
@syropian
I'm not sure I follow your solution. I'm using Laravel Mix and Vue single file components.
I split my main SASS file into two: preflight with just @tailwind preflight in it and utilities with @tailwind utilities and an import for custom classes covering what Tailwind can't do.
Since Tailwind 0.6.2 you can use shadowLookup to apply classes that aren't defined but would exist if @tailwind utilities was included in the same CSS file. See the release notes.
module.exports={// ...options: {prefix: '',important: false,separator: ':',shadowLookup: true,// Should be official feature now},experiments: {shadowLookup: true,// Added just in case},};
component.vue
<stylelang="scss"scoped>
.cart-bg {
@applybg-black;// Just compiles into a string in css}
.progress-bar {&::-webkit-progress-bar{
@applyw-full;// Just compiles into a string in css}}</style>
UPDATE: Fixed by updating to unreleased laravel-mix version 4.0.12 which addresses this problem
Activity
reinink commentedon Nov 1, 2017
Amazing! Thanks for testing this Collin. Very cool that it just works, but I guess that sort of makes sense. Are we good to close this issue then?
syropian commentedon Nov 1, 2017
Yep! Closing.
unxsist commentedon Nov 3, 2017
Hi @syropian,
Can you show me your mix setup? I'm struggling with setting it up the way you suggested. My extracted Vue styles are just being inserted in between the output of preflight and utilities, but they're not being processed by PostCSS.
LannyBose commentedon Nov 4, 2017
@syropian and @reinink, I'm hitting the same wall as @unxsist... Keep getting
unable to find .bg-bluewhen trying to@applyin me Vue component... What's the mix config that could get me home here?syropian commentedon Nov 9, 2017
@unxsist @lperiodbose Unfortunately you have to include
@tailwind utilities;in your style block. The very unfortunate side effect being this duplicates all of Tailwind into the output and your CSS file will row exponentially. More on this issue can be found here: #150adamwathan commentedon Nov 9, 2017
So I can think of a few ways that we could make it possible to
@applyclasses that aren't defined in the same scope:Add some sort of
@silent { ... }at-rule for generating the utilities so they are available when@applyruns but stripped by the time Tailwind is totally finished:Make Tailwind always fallback to looking for a matching utility in the utilities it would generate, even if they haven't been generated into the current scope. So
@apply .bg-redwould work as long as Tailwind would generate that utility if you did add@tailwind utilitiesto that file.The only thing I dislike about this approach is it doesn't let you use
@applyfor custom utilities that aren't generated by Tailwind like you can normally.I'm somewhat hesitant to solve this problem because I really don't want to encourage people to start using Tailwind solely as a library for building component classes, but if it's really a big problem for people then maybe we can try something.
alexsasharegan commentedon Feb 28, 2018
Is there a solution for this that Vue users not using Mix could implement? It looks like
@silentis not implemented. I'm just setting up tailwind in a large Vue project, and I honestly don't know yet how I'll need/want to compose with@apply, but it's advertised in the documentation by virtue of the Extracting Components section. Usage in a single file component environment shouldn't preclude me from being able to compose things in that environment, right?Especially if I'm going to use tailwind as the primary source of truth for a color palette.Possibly confusing my setup is the fact that SCSS is already implemented, so style blocks in vue are using that lang attribute.Update
Looks like the failures to compile the
@applyrules were breaking the color config usage. Color config works fine once all errors are fixed.r0skar commentedon Feb 28, 2018
@alexsasharegan FYI you can use the
confighelper like this:without including
@tailwind utilities;in the Vue component. However, I have not been able to make@applywork without including@tailwind utilities;.alexsasharegan commentedon Feb 28, 2018
Thanks @r0skar, I updated my comment when I figured out that the broken
@applywas also breakingconfig(). That's working now that I've removed all my attempts at@apply.wishinghand commentedon May 18, 2018
@syropian
I'm not sure I follow your solution. I'm using Laravel Mix and Vue single file components.
I split my main SASS file into two: preflight with just
@tailwind preflightin it and utilities with@tailwind utilitiesand an import for custom classes covering what Tailwind can't do.In my
webpack.mix.jsfile it looks like this:This isn't working.
extractVueStylesand Mix's.combine()method are undocumented so I'm not sure how to get them to work.Wurielle commentedon Sep 13, 2018
Since Tailwind 0.6.2 you can use
shadowLookupto apply classes that aren't defined but would exist if@tailwind utilitieswas included in the same CSS file. See the release notes.However, this feature is disabled by default behind flags. It is also stated that this features may be changed or removed at any time without any regard for semantic versioning.
If you still wish to enable it, add this to your tailwind config file:
You can then use your stylesheet like you normally would:
stephenkoo commentedon Dec 27, 2018
@Wurielle Am I doing something wrong? What happens is styles
@apply w-full;gets compiled as css (as a string).webpack.mix.js
tailwind.js
component.vue
UPDATE: Fixed by updating to unreleased
laravel-mixversion4.0.12which addresses this problemMerge pull request tailwindlabs#1 from wtoalabi/wtoalabi-patch-1
Merge pull request tailwindlabs#1 from tailwindcss/next
2 remaining items
feat/performance improvements (#1)
improvement #1: ignore known invalid candidates
Cleanup oxide — Part #1 (#13304)
ensure `anchor-size` can be used in arbitrary values
ensure `anchor-size` can be used in arbitrary values
ensure `anchor-size` can be used in arbitrary values
ensure `anchor-size` can be used in arbitrary values
improve algorithm
improve algorithm
improve algorithm
improve algorithm
improve algorithm
improve algorithm
improve algorithm
Don't warn about Angular's `::ng-deep` and `:host-context()` when opt…