Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Class detection in custom Vue directive #17946

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

Closed
ronaldtb opened this issue May 9, 2025 · 0 comments
Closed

Class detection in custom Vue directive #17946

ronaldtb opened this issue May 9, 2025 · 0 comments

Comments

@ronaldtb
Copy link

ronaldtb commented May 9, 2025

What version of Tailwind CSS are you using?

v4.1.5

What build tool (or framework if it abstracts the build tool) are you using?

Vite v6.3.5

What version of Node.js are you using?

v22.14.0

Describe your issue

We have bought TailwindUI / Plus for our company and are very happy with the components and templates.
One of the best features is the ability to copy and paste the code for quick prototyping.

But now we are working in a Vue 3 project where we need to use a prefix (for example @import "tailwindcss" prefix(cst); and this breaks the ability to quickly copy and paste the code, because we need to manually prefix all the classes.

To workaround this issue I was thinking about the following custom Vue directive:

const vTailwind = {
  mounted: (el: HTMLElement, binding: DirectiveBinding<string>) => {
    // Add prefixed classes to class list
    if (binding.value) {
      binding.value
        .split(' ')
        .map(v => 'cst:' + v)
        .forEach(v => el.classList.add(v));
    }
  }
}

This allows us to specify the classes without the prefix, like:

<div v-tailwind="'px-4 sm:px-6 lg:px-8'">

Unfortunately this breaks the class detection, because it requires the prefix to be included in the actual source file.

Is there maybe a solution available to handle this? For example being able to specify a source prefix and a separate build prefix?

@wongjn wongjn converted this issue into discussion #17947 May 9, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant