Performance: Preset sharing across projects
This affects the build time and bundle size by reusing shared Tailwind configurations across projects.
/* Create a shared preset package with common Tailwind config */ // shared-preset/index.js module.exports = { theme: { extend: { colors: { brand: '#123456' } } }, plugins: [] }; // In each project tailwind.config.js const sharedPreset = require('shared-preset'); module.exports = { presets: [sharedPreset], theme: { extend: { spacing: { '72': '18rem' } } } };
/* Each project has its own full tailwind.config.js with duplicated settings */ module.exports = { theme: { extend: { colors: { brand: '#123456' } } }, plugins: [] };
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Duplicated Tailwind configs per project | No change | No change | Higher due to larger CSS | [X] Bad |
| Shared Tailwind preset across projects | No change | No change | Lower due to smaller CSS | [OK] Good |
presets in Tailwind CSS configuration?tailwind.config.js?presets (plural) and it expects an array of required modules.presets with an array containing require('tailwind-preset'), which is correct syntax.tailwind.config.js snippet, what will be the background color of a div with class bg-primary?
module.exports = {
presets: [require('./shared-preset')],
theme: {
extend: {
colors: {
primary: '#ff0000'
}
}
}
}
And the shared-preset.js contains:
module.exports = {
theme: {
colors: {
primary: '#00ff00'
}
}
}primary color '#ff0000' overrides preset '#00ff00'.bg-primarytailwind.config.js but your styles from the preset are not applying. What is the most likely mistake?preset (singular) instead of presets (plural) means Tailwind ignores the preset array.module.exports is possible but less common; C and D are unrelated to preset loading.preset instead of presets in config -> Option Apresets array lets each project override colors locally without changing the shared preset.presets array; override colors locally as needed -> Option DPass the test and this pattern moves unknown