Skip to content

Workflow to use Tailwind in Vue components? #1

Closed
@syropian

Description

@syropian

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. 🎉

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions