It does indeed strip it out. But you can safelist those you want to keep always (with regex even) https://tailwindcss.com/docs/content-configuration#safelisting-classes
Vue 3 and Tailwind computed properties
In the past I have used the excellent bootstrap-vue component set but hey if you are using Jetstream or Breeze with Intetia there is no bootstrap option. You have and use Tailwind and we all know that Tailwind and Bootstrap don't play well together. So I am building out a library of Vue 3 components.
Tailwind is great but there are some weaknesses. Let's take for example a button that might be used in various places through the application.
<template>
<button class="bg-slate-500 hover:bg-slate-700 transition-colors ease-in text-white font-bold py-2 px-4 rounded font-light"><slot></slot></button>
</template>
you might use it like this
<tw-button @click="createProducts" >Create</tw-button>
and you could override the background color by doing this:
<tw-button @click="createProducts" class="bg-indigo-500" >Create</tw-button>
That would work BUT what happens when someone (the client) says - "you know what I think the buttons should be green".
If you have lots of buttons that might need a real pain to find even with a fancy IDE like phpStorm.
One partial workaround would be to create a color alias in tailwind.config.js
const colors = require('tailwindcss/colors')
...
theme: {
extend: {
colors:{
primary:colors.cyan,
secondary:colors.lime
}
},
},
...
One could then code the button like this:
<tw-button @click="createProducts" class="bg-primary-500" >Create</tw-button>
Now if you want to change the color globally you can do it in the tailwind.config.js file.
Frustratingly what you cannot do is something like this in your component:
<template>
<button :class="bgcolor" class="hover:bg-slate-700 transition-colors ease-in text-white font-bold py-2 px-4 rounded font-light"><slot></slot></button>
</template>
<script>
export default {
props: {
color: {
type: String,
default: 'slate'
}
},
computed: {
bgcolor() {
return 'bg-'+this.color+'-500'
}
},
}
</script>
I think that this is because Tailwind strips out all the classes it can't find in the files using preg match but for what ever reason it is a quite pain. I can't be the only disappointed user. Does anyone know of a good solution to creating dynamic tailwind classes that?
Please or to participate in this conversation.