UNPKG

assetgraph

Version:

An auto discovery dependency graph based optimization framework for web pages and applications

22 lines (20 loc) 577 B
// https://github.com/One-com/assetgraph/issues/82 module.exports = queryObj => { return function removeDuplicateHtmlStyles(assetGraph) { for (const htmlAsset of assetGraph.findAssets( Object.assign({ type: 'Html' }, queryObj) )) { const seenCssAssets = new Set(); for (const htmlStyle of assetGraph.findRelations({ from: htmlAsset, type: 'HtmlStyle' })) { if (seenCssAssets.has(htmlStyle.to)) { htmlStyle.detach(); } else { seenCssAssets.add(htmlStyle.to); } } } }; };