Performance: Plugin system overview
Tailwind plugins affect build time and CSS bundle size, impacting page load speed and rendering performance.
module.exports = {
plugins: [
require('@tailwindcss/forms'),
require('@tailwindcss/typography')
]
}module.exports = {
plugins: [
function({ addUtilities }) {
addUtilities({
'.custom-shadow': {
boxShadow: '0 4px 6px rgba(0,0,0,0.1)',
filter: 'drop-shadow(0 0 5px rgba(0,0,0,0.2))'
}
})
}
]
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy custom plugin utilities | No direct DOM impact | No direct reflows | High paint cost due to large CSS | [X] Bad |
| Official lightweight plugins | No direct DOM impact | No direct reflows | Lower paint cost with smaller CSS | [OK] Good |
plugin().plugin() correctly with a function argument.const plugin = require('tailwindcss/plugin')
module.exports = plugin(function({ addUtilities }) {
addUtilities({
'.text-shadow': {
'text-shadow': '2px 2px #ff0000'
}
})
})addUtilities to add a new CSS utility class..text-shadow applies a red text shadow style.const plugin = require('tailwindcss/plugin')
module.exports = plugin(function({ addComponents }) {
addComponents({
'.btn': {
padding: '1rem',
backgroundColor: 'blue'
}
})
})backgroundColor should be background-color as a string key..card-shadow with a subtle box shadow, but only when the screen width is at least 768px. Which approach correctly uses the plugin system to achieve this?addUtilities with a media query inside the CSS object is the correct way.Pass the test and this pattern moves unknown