Tailwind version: v9.3.5
PostCSS Config:
// postcss.config.js
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
...(process.env.NODE_ENV === 'production'
? {
'@fullhuman/postcss-purgecss': {
content: ['./components/**/*.js', './pages/**/*.js'],
defaultExtractor: content =>
content.match(/[\w-/:]+(?<!:)/g) || [],
},
}
: {}),
},
}
Tailwind Config:
// tailwind.config.js
module.exports = {
theme: {
extend: {
colors: {
tint: 'rgba(0,0,0,0.3)',
},
},
},
variants: {},
plugins: [],
}
Styles work perfectly in development but in production only some styling is working. Upon checking the CSS file in build folder, looks like some of the CSS classes are not being extracted or possibly purged therefore resulting in partial styling of the app.
It's pretty easy to enable the JIT compiler. All you have to do is update your tailwind. config. js file by adding the mode property which should have a value of 'jit'.
These CSS classes are the main reason why building and styling with Tailwind is so fast. With Tailwind's pre-built classes, you can design the layout directly in an HTML file. This makes it a very responsive, mobile-friendly CSS framework.
EDIT : PurgeCSS version 3.0 add safelist option, replace whitelist
I faced the same problem when i dynamically inject name of some classes into my html template.
I am using nuxt.js/tailwindcss so you need to read the documentary first to solve your problem.
here's the code who generate the classes missing in production
computed: {
axeY() {
return this.y < 0 ? `-translate-y${this.y}` + ' ' : `translate-y-1` + ' '
},
axeX() {
return this.x < 0 ? `-translate-x${this.x}` : `translate-x-${this.x}`
},
PostCSS will analyse all files into the content table (declaring in the config file),
noted that my files doesn't include classes with translate prefix
as you can see, my missing classes are: [translate-x-1,-translate-x-1, translate-y-1, -translate-y-1] ... the number 1 is a variable.
You can specify content that should be analyzed by PurgeCSS with an array of filenames
/*
** TailwindCSS Configuration File
**
** Docs: https://tailwindcss.com/docs/configuration
** Default: https://github.com/tailwindcss/tailwindcss/blob/master/stubs/defaultConfig.stub.js
*/
const num = [1, 2, 3, 4, 5, 6, 8, 10, 12]
const whitelist = []
num.map((x) => {
whitelist.push('translate-x-' + x)
whitelist.push('-translate-x-' + x)
whitelist.push('translate-y-' + x)
whitelist.push('-translate-y-' + x)
})
module.exports = {
future: {
removeDeprecatedGapUtilities: true,
},
theme: {},
variants: {
backgroundColor: ['hover', 'focus', 'active'],
},
plugins: [],
purge: {
// Learn more on https://tailwindcss.com/docs/controlling-file-size/#removing-unused-css
enabled: process.env.NODE_ENV === 'production',
content: [
'components/**/*.vue',
'layouts/**/*.vue',
'pages/**/*.vue',
'plugins/**/*.js',
'nuxt.config.js',
],
options: {
whitelist,
},
},
}
Found the issue, postcss
config was missing sections folder in content array and also since my js files had jsx
, i need to add that as well.
// postcss.config.js
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
...(process.env.NODE_ENV === 'production'
? {
'@fullhuman/postcss-purgecss': {
// added sections folder and changed extension to jsx
content: ['./components/**/*.jsx', './pages/**/*.js', './sections/**/**/*.jsx'],
defaultExtractor: content =>
content.match(/[\w-/:]+(?<!:)/g) || [],
},
}
: {}),
},
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With