|
| 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