Skip to content

Commit 5c61089

Browse files
committed
Fix: Add plugin to prevent CSS minifier from breaking Tailwind CSS v4 output
1 parent 3da2839 commit 5c61089

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

docusaurus.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ const config = {
7979
},
8080
}),
8181

82+
plugins: [
83+
require.resolve('./plugins/fix-css-minification'),
84+
],
8285
};
8386

8487
module.exports = config;

plugins/fix-css-minification.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Docusaurus plugin to fix CSS minification issues with Tailwind CSS v4
3+
* This prevents the CSS minifier from breaking Tailwind's output
4+
*/
5+
function fixCssMinification(context, options) {
6+
return {
7+
name: 'fix-css-minification',
8+
configureWebpack(config, isServer, utils) {
9+
if (isServer) {
10+
return {};
11+
}
12+
13+
// Find and configure CSS minimizer
14+
const minimizerPlugins = config.optimization?.minimizer || [];
15+
16+
minimizerPlugins.forEach((plugin) => {
17+
// Check if this is the CSS minimizer plugin
18+
if (plugin && plugin.constructor && plugin.constructor.name === 'CssMinimizerPlugin') {
19+
// Configure to be less aggressive and preserve Tailwind CSS v4 syntax
20+
if (plugin.options) {
21+
plugin.options.minimizerOptions = {
22+
preset: [
23+
'default',
24+
{
25+
// Don't break modern CSS features
26+
discardComments: { removeAll: false },
27+
normalizeWhitespace: false,
28+
// Critical: Don't minify keyframes names or break animations
29+
reduceIdents: false,
30+
// Don't merge rules that might break Tailwind
31+
mergeRules: false,
32+
// Preserve CSS variables
33+
reduceTransforms: false,
34+
// Don't break @supports queries
35+
discardUnused: false,
36+
// Preserve important comments
37+
minifySelectors: true,
38+
minifyParams: true,
39+
minifyFontValues: true,
40+
minifyGradients: true,
41+
minifyTimingFunctions: true,
42+
},
43+
],
44+
};
45+
}
46+
}
47+
});
48+
49+
return {};
50+
},
51+
};
52+
}
53+
54+
module.exports = fixCssMinification;
55+

0 commit comments

Comments
 (0)