PurgeCSS Removing MDX Styles in Nextjs Despite Being Included in Purge Content Option #3017
-
Hey all, so I have a Nextjs project that has some mdx pages for the docs section of the site. Everything is running fine locally, but when I deployed to vercel yesterday I noticed that my mdx pages were getting purged. I double checked that the content config included mdx files, but it's still wiping those styles. I was able to confirm that it was a purge issue by setting I even tried explicitly calling out the docs path in my purge settings. What am I missing? purge: {
content:[
'./src/**/*.{js,jsx,mdx}',
'./src/pages/docs/*.mdx',
]
}, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
So in my myriad of code iterations, I gave this a go and it works... not sure why, but I'll take it. weird. If anyone else is using this in the future, obviously make sure you take out the purge: {
enabled: true,
content:[
'./src/**/*.js',
'./*/*.{js,mdx}',
]
}, |
Beta Was this translation helpful? Give feedback.
-
@simonswiss any thoughts on why this is in case anyone else comes across this? Would be nice to know, but as long as it works, I guess I'm happy 😆 |
Beta Was this translation helpful? Give feedback.
-
Hey! Would it be possible to have a look at that repo? What version of Tailwind are you on? What does your Tailwind config look like? |
Beta Was this translation helpful? Give feedback.
-
Hola! I had a look at your repo shared above, and I figured out what's happening. The That class is actually only present in plain text (what Purge CSS cares about) in the For that reason, purge strips out the Your solution is to add the path to that purge: {
content: [
"./src/**/*.{js,mdx}",
+ "./remark/withProse.js"
],
}, or purge: {
content: ["./src/**/*.{js,mdx}"],
+ options: {
+ safelist: ["prose"],
+ },
}, Hope it helps you understand what was happening! 🎉 |
Beta Was this translation helpful? Give feedback.
Hola!
I had a look at your repo shared above, and I figured out what's happening.
The
prose
class name, which is responsible for applying all the styles from the Typography plugin, is nowhere to be found on any of the files within./src/**/*.*
That class is actually only present in plain text (what Purge CSS cares about) in the
withProse
file within theremark
folder.For that reason, purge strips out the
prose
class and kills all the Typography styles you rely on for the docs pages!Your solution is to add the path to that
withProse
file in yourpurge.content
array, or addprose
as apurge.options.safelist
value:purge: { content: [ "./src/**/*.{js,mdx}", + "./remark/withProse.js"