I'm trying to generate a CSS file that only includes colors (backgrounds, text, borders, etc). I couldn't find anything in the documentation about creating a config that generates an empty file or works in a 'whitelist' manner. I tried to set everything to false, but there is still about 5kb of CSS being generated.
I think there should be a way to write a config file that only includes specified options. If there already is, can someone provide me a solution?
Here is my attempt at setting everything in the config to false:
module.exports = {
prefix: '',
important: false,
separator: '',
theme: {
container: false,
preflight: false,
screens: false,
colors: false,
spacing: false,
alignContent: false,
alignItems: false,
alignSelf: false,
appearance: false,
backgroundAttachment: false,
backgroundColor: false,
backgroundPosition: false,
backgroundRepeat: false,
backgroundSize: false,
borderCollapse: false,
borderColor: false,
borderRadius: false,
borderStyle: false,
borderWidth: false,
boxShadow: false,
cursor: false,
display: false,
fill: false,
flex: false,
flexDirection: false,
flexGrow: false,
flexShrink: false,
flexWrap: false,
float: false,
fontFamily: false,
fontSize: false,
fontSmoothing: false,
fontStyle: false,
fontWeight: false,
height: false,
inset: false,
justifyContent: false,
letterSpacing: false,
lineHeight: false,
listStylePosition: false,
listStyleType: false,
margin: false,
maxHeight: false,
maxWidth: false,
minHeight: false,
minWidth: false,
negativeMargin: false,
objectFit: false,
objectPosition: false,
opacity: false,
order: false,
outline: false,
overflow: false,
padding: false,
placeholderColor: false,
pointerEvents: false,
position: false,
resize: false,
stroke: false,
tableLayout: false,
textAlign: false,
textColor: false,
textDecoration: false,
textTransform: false,
userSelect: false,
verticalAlign: false,
visibility: false,
whitespace: false,
width: false,
wordBreak: false,
zIndex: false,
},
variants: {
alignContent: false,
alignItems: false,
alignSelf: false,
appearance: false,
backgroundAttachment: false,
backgroundColor: false,
backgroundPosition: false,
backgroundRepeat: false,
backgroundSize: false,
borderCollapse: false,
borderColor: false,
borderRadius: false,
borderStyle: false,
borderWidth: false,
boxShadow: false,
cursor: false,
display: false,
fill: false,
flex: false,
flexDirection: false,
flexGrow: false,
flexShrink: false,
flexWrap: false,
float: false,
fontFamily: false,
fontSize: false,
fontSmoothing: false,
fontStyle: false,
fontWeight: false,
height: false,
inset: false,
justifyContent: false,
letterSpacing: false,
lineHeight: false,
listStylePosition: false,
listStyleType: false,
margin: false,
maxHeight: false,
maxWidth: false,
minHeight: false,
minWidth: false,
negativeMargin: false,
objectFit: false,
objectPosition: false,
opacity: false,
order: false,
outline: false,
overflow: false,
padding: false,
placeholderColor: false,
pointerEvents: false,
position: false,
resize: false,
stroke: false,
tableLayout: false,
textAlign: false,
textColor: false,
textDecoration: false,
textTransform: false,
userSelect: false,
verticalAlign: false,
visibility: false,
whitespace: false,
width: false,
wordBreak: false,
zIndex: false,
},
// corePlugins: {},
plugins: [],
}
@ZebTheWizard What you're looking for is corePlugins. You can set it to an array to disable all core plugins but the ones you specify:
corePlugins: ['textColor']
No need to reset anything under theme or variants.
@ZebTheWizard What you're looking for is
corePlugins. You can set it to an array to disable all core plugins but the ones you specify:corePlugins: ['textColor']No need to reset anything under
themeorvariants.
So how can I do the same thing for variants? When I specify just one variant, all the default variants are included.
@ZebTheWizard Can you share your config? Passing an array to variants should only include the specified variants for all utilities: https://tailwindcss.com/docs/configuring-variants/#enabling-all-variants
I only want the variants for width.
variants: {
width: ['responsive']
}
If you only want to generate width utilities and only the responsive variants for those utilities, you would make a config that looks like this:
module.exports = {
corePlugins: ['width'],
variants: {
width: ['responsive']
},
}
That will output the following CSS when you compile:
.w-0 {
width: 0
}
.w-1 {
width: 0.25rem
}
.w-2 {
width: 0.5rem
}
.w-3 {
width: 0.75rem
}
.w-4 {
width: 1rem
}
.w-5 {
width: 1.25rem
}
.w-6 {
width: 1.5rem
}
.w-8 {
width: 2rem
}
.w-10 {
width: 2.5rem
}
.w-12 {
width: 3rem
}
.w-16 {
width: 4rem
}
.w-20 {
width: 5rem
}
.w-24 {
width: 6rem
}
.w-32 {
width: 8rem
}
.w-40 {
width: 10rem
}
.w-48 {
width: 12rem
}
.w-56 {
width: 14rem
}
.w-64 {
width: 16rem
}
.w-auto {
width: auto
}
.w-px {
width: 1px
}
.w-1\/2 {
width: 50%
}
.w-1\/3 {
width: 33.333333%
}
.w-2\/3 {
width: 66.666667%
}
.w-1\/4 {
width: 25%
}
.w-2\/4 {
width: 50%
}
.w-3\/4 {
width: 75%
}
.w-1\/5 {
width: 20%
}
.w-2\/5 {
width: 40%
}
.w-3\/5 {
width: 60%
}
.w-4\/5 {
width: 80%
}
.w-1\/6 {
width: 16.666667%
}
.w-2\/6 {
width: 33.333333%
}
.w-3\/6 {
width: 50%
}
.w-4\/6 {
width: 66.666667%
}
.w-5\/6 {
width: 83.333333%
}
.w-1\/12 {
width: 8.333333%
}
.w-2\/12 {
width: 16.666667%
}
.w-3\/12 {
width: 25%
}
.w-4\/12 {
width: 33.333333%
}
.w-5\/12 {
width: 41.666667%
}
.w-6\/12 {
width: 50%
}
.w-7\/12 {
width: 58.333333%
}
.w-8\/12 {
width: 66.666667%
}
.w-9\/12 {
width: 75%
}
.w-10\/12 {
width: 83.333333%
}
.w-11\/12 {
width: 91.666667%
}
.w-full {
width: 100%
}
.w-screen {
width: 100vw
}
@media (min-width: 640px) {
.sm\:w-0 {
width: 0
}
.sm\:w-1 {
width: 0.25rem
}
.sm\:w-2 {
width: 0.5rem
}
.sm\:w-3 {
width: 0.75rem
}
.sm\:w-4 {
width: 1rem
}
.sm\:w-5 {
width: 1.25rem
}
.sm\:w-6 {
width: 1.5rem
}
.sm\:w-8 {
width: 2rem
}
.sm\:w-10 {
width: 2.5rem
}
.sm\:w-12 {
width: 3rem
}
.sm\:w-16 {
width: 4rem
}
.sm\:w-20 {
width: 5rem
}
.sm\:w-24 {
width: 6rem
}
.sm\:w-32 {
width: 8rem
}
.sm\:w-40 {
width: 10rem
}
.sm\:w-48 {
width: 12rem
}
.sm\:w-56 {
width: 14rem
}
.sm\:w-64 {
width: 16rem
}
.sm\:w-auto {
width: auto
}
.sm\:w-px {
width: 1px
}
.sm\:w-1\/2 {
width: 50%
}
.sm\:w-1\/3 {
width: 33.333333%
}
.sm\:w-2\/3 {
width: 66.666667%
}
.sm\:w-1\/4 {
width: 25%
}
.sm\:w-2\/4 {
width: 50%
}
.sm\:w-3\/4 {
width: 75%
}
.sm\:w-1\/5 {
width: 20%
}
.sm\:w-2\/5 {
width: 40%
}
.sm\:w-3\/5 {
width: 60%
}
.sm\:w-4\/5 {
width: 80%
}
.sm\:w-1\/6 {
width: 16.666667%
}
.sm\:w-2\/6 {
width: 33.333333%
}
.sm\:w-3\/6 {
width: 50%
}
.sm\:w-4\/6 {
width: 66.666667%
}
.sm\:w-5\/6 {
width: 83.333333%
}
.sm\:w-1\/12 {
width: 8.333333%
}
.sm\:w-2\/12 {
width: 16.666667%
}
.sm\:w-3\/12 {
width: 25%
}
.sm\:w-4\/12 {
width: 33.333333%
}
.sm\:w-5\/12 {
width: 41.666667%
}
.sm\:w-6\/12 {
width: 50%
}
.sm\:w-7\/12 {
width: 58.333333%
}
.sm\:w-8\/12 {
width: 66.666667%
}
.sm\:w-9\/12 {
width: 75%
}
.sm\:w-10\/12 {
width: 83.333333%
}
.sm\:w-11\/12 {
width: 91.666667%
}
.sm\:w-full {
width: 100%
}
.sm\:w-screen {
width: 100vw
}
}
@media (min-width: 768px) {
.md\:w-0 {
width: 0
}
.md\:w-1 {
width: 0.25rem
}
.md\:w-2 {
width: 0.5rem
}
.md\:w-3 {
width: 0.75rem
}
.md\:w-4 {
width: 1rem
}
.md\:w-5 {
width: 1.25rem
}
.md\:w-6 {
width: 1.5rem
}
.md\:w-8 {
width: 2rem
}
.md\:w-10 {
width: 2.5rem
}
.md\:w-12 {
width: 3rem
}
.md\:w-16 {
width: 4rem
}
.md\:w-20 {
width: 5rem
}
.md\:w-24 {
width: 6rem
}
.md\:w-32 {
width: 8rem
}
.md\:w-40 {
width: 10rem
}
.md\:w-48 {
width: 12rem
}
.md\:w-56 {
width: 14rem
}
.md\:w-64 {
width: 16rem
}
.md\:w-auto {
width: auto
}
.md\:w-px {
width: 1px
}
.md\:w-1\/2 {
width: 50%
}
.md\:w-1\/3 {
width: 33.333333%
}
.md\:w-2\/3 {
width: 66.666667%
}
.md\:w-1\/4 {
width: 25%
}
.md\:w-2\/4 {
width: 50%
}
.md\:w-3\/4 {
width: 75%
}
.md\:w-1\/5 {
width: 20%
}
.md\:w-2\/5 {
width: 40%
}
.md\:w-3\/5 {
width: 60%
}
.md\:w-4\/5 {
width: 80%
}
.md\:w-1\/6 {
width: 16.666667%
}
.md\:w-2\/6 {
width: 33.333333%
}
.md\:w-3\/6 {
width: 50%
}
.md\:w-4\/6 {
width: 66.666667%
}
.md\:w-5\/6 {
width: 83.333333%
}
.md\:w-1\/12 {
width: 8.333333%
}
.md\:w-2\/12 {
width: 16.666667%
}
.md\:w-3\/12 {
width: 25%
}
.md\:w-4\/12 {
width: 33.333333%
}
.md\:w-5\/12 {
width: 41.666667%
}
.md\:w-6\/12 {
width: 50%
}
.md\:w-7\/12 {
width: 58.333333%
}
.md\:w-8\/12 {
width: 66.666667%
}
.md\:w-9\/12 {
width: 75%
}
.md\:w-10\/12 {
width: 83.333333%
}
.md\:w-11\/12 {
width: 91.666667%
}
.md\:w-full {
width: 100%
}
.md\:w-screen {
width: 100vw
}
}
@media (min-width: 1024px) {
.lg\:w-0 {
width: 0
}
.lg\:w-1 {
width: 0.25rem
}
.lg\:w-2 {
width: 0.5rem
}
.lg\:w-3 {
width: 0.75rem
}
.lg\:w-4 {
width: 1rem
}
.lg\:w-5 {
width: 1.25rem
}
.lg\:w-6 {
width: 1.5rem
}
.lg\:w-8 {
width: 2rem
}
.lg\:w-10 {
width: 2.5rem
}
.lg\:w-12 {
width: 3rem
}
.lg\:w-16 {
width: 4rem
}
.lg\:w-20 {
width: 5rem
}
.lg\:w-24 {
width: 6rem
}
.lg\:w-32 {
width: 8rem
}
.lg\:w-40 {
width: 10rem
}
.lg\:w-48 {
width: 12rem
}
.lg\:w-56 {
width: 14rem
}
.lg\:w-64 {
width: 16rem
}
.lg\:w-auto {
width: auto
}
.lg\:w-px {
width: 1px
}
.lg\:w-1\/2 {
width: 50%
}
.lg\:w-1\/3 {
width: 33.333333%
}
.lg\:w-2\/3 {
width: 66.666667%
}
.lg\:w-1\/4 {
width: 25%
}
.lg\:w-2\/4 {
width: 50%
}
.lg\:w-3\/4 {
width: 75%
}
.lg\:w-1\/5 {
width: 20%
}
.lg\:w-2\/5 {
width: 40%
}
.lg\:w-3\/5 {
width: 60%
}
.lg\:w-4\/5 {
width: 80%
}
.lg\:w-1\/6 {
width: 16.666667%
}
.lg\:w-2\/6 {
width: 33.333333%
}
.lg\:w-3\/6 {
width: 50%
}
.lg\:w-4\/6 {
width: 66.666667%
}
.lg\:w-5\/6 {
width: 83.333333%
}
.lg\:w-1\/12 {
width: 8.333333%
}
.lg\:w-2\/12 {
width: 16.666667%
}
.lg\:w-3\/12 {
width: 25%
}
.lg\:w-4\/12 {
width: 33.333333%
}
.lg\:w-5\/12 {
width: 41.666667%
}
.lg\:w-6\/12 {
width: 50%
}
.lg\:w-7\/12 {
width: 58.333333%
}
.lg\:w-8\/12 {
width: 66.666667%
}
.lg\:w-9\/12 {
width: 75%
}
.lg\:w-10\/12 {
width: 83.333333%
}
.lg\:w-11\/12 {
width: 91.666667%
}
.lg\:w-full {
width: 100%
}
.lg\:w-screen {
width: 100vw
}
}
@media (min-width: 1280px) {
.xl\:w-0 {
width: 0
}
.xl\:w-1 {
width: 0.25rem
}
.xl\:w-2 {
width: 0.5rem
}
.xl\:w-3 {
width: 0.75rem
}
.xl\:w-4 {
width: 1rem
}
.xl\:w-5 {
width: 1.25rem
}
.xl\:w-6 {
width: 1.5rem
}
.xl\:w-8 {
width: 2rem
}
.xl\:w-10 {
width: 2.5rem
}
.xl\:w-12 {
width: 3rem
}
.xl\:w-16 {
width: 4rem
}
.xl\:w-20 {
width: 5rem
}
.xl\:w-24 {
width: 6rem
}
.xl\:w-32 {
width: 8rem
}
.xl\:w-40 {
width: 10rem
}
.xl\:w-48 {
width: 12rem
}
.xl\:w-56 {
width: 14rem
}
.xl\:w-64 {
width: 16rem
}
.xl\:w-auto {
width: auto
}
.xl\:w-px {
width: 1px
}
.xl\:w-1\/2 {
width: 50%
}
.xl\:w-1\/3 {
width: 33.333333%
}
.xl\:w-2\/3 {
width: 66.666667%
}
.xl\:w-1\/4 {
width: 25%
}
.xl\:w-2\/4 {
width: 50%
}
.xl\:w-3\/4 {
width: 75%
}
.xl\:w-1\/5 {
width: 20%
}
.xl\:w-2\/5 {
width: 40%
}
.xl\:w-3\/5 {
width: 60%
}
.xl\:w-4\/5 {
width: 80%
}
.xl\:w-1\/6 {
width: 16.666667%
}
.xl\:w-2\/6 {
width: 33.333333%
}
.xl\:w-3\/6 {
width: 50%
}
.xl\:w-4\/6 {
width: 66.666667%
}
.xl\:w-5\/6 {
width: 83.333333%
}
.xl\:w-1\/12 {
width: 8.333333%
}
.xl\:w-2\/12 {
width: 16.666667%
}
.xl\:w-3\/12 {
width: 25%
}
.xl\:w-4\/12 {
width: 33.333333%
}
.xl\:w-5\/12 {
width: 41.666667%
}
.xl\:w-6\/12 {
width: 50%
}
.xl\:w-7\/12 {
width: 58.333333%
}
.xl\:w-8\/12 {
width: 66.666667%
}
.xl\:w-9\/12 {
width: 75%
}
.xl\:w-10\/12 {
width: 83.333333%
}
.xl\:w-11\/12 {
width: 91.666667%
}
.xl\:w-full {
width: 100%
}
.xl\:w-screen {
width: 100vw
}
}
@ZebTheWizard Ah, and you want no variants at all for all the other core plugins? If that's the case, then yeah unfortunately you will have to set them all to an empty array I'm afraid...
variants: {
alignContent: [],
alignItems: [],
alignSelf: [],
appearance: [],
backgroundAttachment: [],
backgroundColor: [],
backgroundPosition: [],
backgroundRepeat: [],
backgroundSize: [],
borderCollapse: [],
borderColor: [],
borderRadius: [],
borderStyle: [],
borderWidth: [],
boxShadow: [],
cursor: [],
display: [],
fill: [],
flex: [],
flexDirection: [],
flexGrow: [],
flexShrink: [],
flexWrap: [],
float: [],
fontFamily: [],
fontSize: [],
fontSmoothing: [],
fontStyle: [],
fontWeight: [],
height: [],
inset: [],
justifyContent: [],
letterSpacing: [],
lineHeight: [],
listStylePosition: [],
listStyleType: [],
margin: [],
maxHeight: [],
maxWidth: [],
minHeight: [],
minWidth: [],
negativeMargin: [],
objectFit: [],
objectPosition: [],
opacity: [],
order: [],
outline: [],
overflow: [],
padding: [],
placeholderColor: [],
pointerEvents: [],
position: [],
resize: [],
stroke: [],
tableLayout: [],
textAlign: [],
textColor: [],
textDecoration: [],
textTransform: [],
userSelect: [],
verticalAlign: [],
visibility: [],
whitespace: [],
width: ['responsive'],
wordBreak: [],
zIndex: [],
},
Of course you can omit the core plugins you're not using (those not in your corePlugins array), so if you have:
corePlugins: ['textColor', 'width']
...then you would only need:
variants: {
textColor: [],
width: ['responsive'],
},
Does that make sense?
By the way, I strongly recommend using Purgecss to control the file size of your generated CSS rather than fiddling with these settings.
That was what I was looking for. I will have to look into purgecss.
Maybe there could be a feature in the config file that would toggle on whitelisting. That way the only code that is generated is whatever is specified in the config and there isn't any guessing, purging, or extra typing.
Glad you were able to get the result you wanted 馃憤 I think #677 will be the best way to avoid default variants being generated and is already captured there so going to close this one.
Most helpful comment
@ZebTheWizard What you're looking for is
corePlugins. You can set it to an array to disable all core plugins but the ones you specify:No need to reset anything under
themeorvariants.