Skip to content

Commit dfc8e34

Browse files
committed
Fix: Improve CSS minifier configuration to better handle Tailwind v4
1 parent 5c61089 commit dfc8e34

File tree

1 file changed

+41
-28
lines changed

1 file changed

+41
-28
lines changed

plugins/fix-css-minification.js

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,48 @@ function fixCssMinification(context, options) {
1313
// Find and configure CSS minimizer
1414
const minimizerPlugins = config.optimization?.minimizer || [];
1515

16-
minimizerPlugins.forEach((plugin) => {
16+
minimizerPlugins.forEach((plugin, index) => {
1717
// 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-
};
18+
// It could be CssMinimizerPlugin or an instance
19+
const pluginName = plugin?.constructor?.name || '';
20+
const isCssMinimizer = pluginName === 'CssMinimizerPlugin' ||
21+
pluginName.includes('CssMinimizer') ||
22+
(plugin.constructor && plugin.constructor.toString().includes('CssMinimizer'));
23+
24+
if (isCssMinimizer) {
25+
// Replace with a safer configuration
26+
try {
27+
// Try to configure the minimizer to be less aggressive
28+
if (plugin.options) {
29+
plugin.options.minimizerOptions = {
30+
preset: [
31+
'default',
32+
{
33+
// Critical: Disable features that break Tailwind CSS v4
34+
discardComments: { removeAll: false },
35+
normalizeWhitespace: false,
36+
reduceIdents: false, // Don't rename keyframes
37+
mergeRules: false, // Don't merge rules
38+
reduceTransforms: false,
39+
discardUnused: false,
40+
// Only safe minifications
41+
minifySelectors: true,
42+
minifyParams: true,
43+
minifyFontValues: true,
44+
minifyGradients: true,
45+
minifyTimingFunctions: true,
46+
},
47+
],
48+
};
49+
}
50+
51+
// Also try to set parallel to false to avoid race conditions
52+
if (plugin.options && typeof plugin.options.parallel !== 'undefined') {
53+
plugin.options.parallel = false;
54+
}
55+
} catch (e) {
56+
// If configuration fails, try to replace the plugin entirely
57+
console.warn('Could not configure CSS minimizer, trying alternative approach');
4558
}
4659
}
4760
});

0 commit comments

Comments
 (0)