diff --git a/lib/subsetFonts.js b/lib/subsetFonts.js index 30f88e42..5c7124f1 100644 --- a/lib/subsetFonts.js +++ b/lib/subsetFonts.js @@ -644,10 +644,6 @@ async function subsetFonts( ], }; - // Keep track of the injected CSS assets that should eventually be minified - // Minifying them along the way currently doesn't work because some of the - // manipulation is sensitive to the exact text contents. We should fix that. - const subsetFontsToBeMinified = new Set(); const fontFaceDeclarationsByHtmlOrSvgAsset = new Map(); const potentiallyOrphanedAssets = new Set(); @@ -1021,7 +1017,7 @@ These glyphs are used on your site, but they don't exist in the font you applied text: subsetCssText, }); - subsetFontsToBeMinified.add(cssAsset); + await cssAsset.minify(); for (const [i, fontRelation] of cssAsset.outgoingRelations.entries()) { const fontAsset = fontRelation.to; @@ -1091,7 +1087,6 @@ These glyphs are used on your site, but they don't exist in the font you applied const existingCssAsset = assetGraph.findAssets({ url: cssAssetUrl })[0]; if (existingCssAsset) { assetGraph.removeAsset(cssAsset); - subsetFontsToBeMinified.delete(cssAsset); cssAsset = existingCssAsset; } else { cssAsset.url = cssAssetUrl; @@ -1226,7 +1221,7 @@ These glyphs are used on your site, but they don't exist in the font you applied assetGraph.removeAsset(cssAsset); cssAsset = existingCssAsset; } else { - subsetFontsToBeMinified.add(cssAsset); + await cssAsset.minify(); cssAsset.url = cssAssetUrl; } @@ -1311,7 +1306,7 @@ These glyphs are used on your site, but they don't exist in the font you applied formats, hrefType ); - subsetFontsToBeMinified.add(selfHostedGoogleFontsCssAsset); + await selfHostedGoogleFontsCssAsset.minify(); selfHostedGoogleCssByUrl.set( googleFontStylesheetRelation.to.url, selfHostedGoogleFontsCssAsset @@ -1492,11 +1487,6 @@ These glyphs are used on your site, but they don't exist in the font you applied } } - // This is a bit awkward now, but if it's done sooner, it breaks the CSS source regexping: - for (const cssAsset of subsetFontsToBeMinified) { - await cssAsset.minify(); - } - await assetGraph.serializeSourceMaps(undefined, { type: 'Css', outgoingRelations: {