Last active
September 26, 2024 15:26
-
-
Save thinkverse/02e4efb8fa11487e0d5e27d5a50e00d5 to your computer and use it in GitHub Desktop.
Useful TailwindCSS config that saves paddings and margins upon build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://v1.tailwindcss.com/docs/controlling-file-size#purge-css-options | |
module.exports = { | |
future: { | |
removeDeprecatedGapUtilities: true, | |
purgeLayersByDefault: true, | |
}, | |
purge: { | |
content: ['./public/**/*.html'], | |
options: { | |
whitelistPatterns: [ | |
/^\-?m(\w?)-/, | |
/^p(\w?)-/, | |
/^text-/, | |
/^bg-/, | |
] | |
} | |
}, | |
theme: { | |
extend: {}, | |
}, | |
variants: {}, | |
plugins: [], | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://v2.tailwindcss.com/docs/optimizing-for-production#safelisting-specific-classes | |
module.exports = { | |
purge: { | |
content: ['./public/**/*.html'], | |
options: { | |
safelist: [ | |
/^\-?m(\w?)-/, | |
/^p(\w?)-/, | |
/^text-/, | |
/^bg-/, | |
] | |
} | |
}, | |
darkMode: false, // or 'media' or 'class' | |
theme: { | |
extend: {}, | |
}, | |
variants: { | |
extend: {}, | |
}, | |
plugins: [], | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://tailwindcss.com/docs/content-configuration#safelisting-classes | |
module.exports = { | |
content: ['./public/**/*.html'], | |
safelist: [ | |
'text-2xl', | |
'text-3xl', | |
{ pattern: /^\-?m(\w?)-/ }, | |
{ pattern: /^p(\w?)-/ }, | |
{ pattern: /^text-/ }, | |
{ pattern: /^bg-/ }, | |
], | |
theme: { | |
extend: {}, | |
}, | |
plugins: [], | |
} |
@hari-d haven't used safelist myself for arbitrary values, but this thread1 on Tailwind's discussions page could be useful for you.
Footnotes
-
Safelist pattern for arbitrary values - https://github.com/tailwindlabs/tailwindcss/discussions/7908 ↩
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to write a pattern for
p-[50px] or m-[50px]
and for all tailwind classes which can be written dynamic using square brackets like the above one.