I have a nuxtjs project that I use with tailwindcss.
In that project I generate classes on the fly for negative margins like so:
<div class="mins-1" :class="['-mt-'+ m1*8]"></div>
The entire project works fine locally, but if I run nuxt build; nuxt start; it gets compiled without errors but none of the dynamic classes seem to work.
So I finally found out that the nuxt build process does some css tree shaking, and since these classes are not included anywhere in the dom, they are not included in the css build process.
To test this I have created a hidden div like so:
<div class="hidden -mt-8 -mt-16 -mt-24 -mt-32 -mt-40 -mt-48 -mt-56 -mt-64 -mt-72 -mt-80">ok needed classes</div>
And voila, that will make my project workable after nuxt build since now the classes needed are present in the dom and will be included.
This seems very hacky!
Now to my question:
What would be the proper way to include dynamically created classes in the build process in a nuxtjs project?
UPDATED tailwind.config.js (Did NOT work with JIT MODE turned on!)
const colors = require("tailwindcss/colors")
module.exports = {
purge: {
enabled: process.env.NODE_ENV === 'production',
content: [
'components/**/*.vue',
'layouts/**/*.vue',
'pages/**/*.vue',
'plugins/**/*.js',
'nuxt.config.js',
// TypeScript
'plugins/**/*.ts',
'nuxt.config.ts'
],
// UPDATE: safelist does NOT work in combination with JIT
options: {
safelist: ['mt-0', '-mt-8', '-mt-16', '-mt-24', '-mt-32', '-mt-40', '-mt-48', '-mt-56', '-mt-64', '-mt-72', '-mt-80'],
}
},
darkMode: false, // or 'media' or 'class'
theme: {
extend: {
colors: {
emerald: colors.emerald,
gray: colors.trueGray,
cyan: colors.cyan
},
},
},
variants: {
extend: {},
},
plugins: [],
}