diff --git a/config/critters-webpack-plugin.js b/config/critters-webpack-plugin.js index fe173756..c1258066 100644 --- a/config/critters-webpack-plugin.js +++ b/config/critters-webpack-plugin.js @@ -39,40 +39,17 @@ module.exports = class CrittersWebpackPlugin { const document = parse5.parse(htmlPluginData.html, PARSE5_OPTS); makeDomInteractive(document); + let externalStylesProcessed = Promise.resolve(); + // `external:false` skips processing of external sheets - const externalSheets = this.options.external===false ? [] : document.querySelectorAll('link[rel="stylesheet"]'); + if (this.options.external!==false) { + const externalSheets = document.querySelectorAll('link[rel="stylesheet"]'); + externalStylesProcessed = Promise.all(externalSheets.map( + link => this.embedLinkedStylesheet(link, compilation, outputPath) + )); + } - Promise.all(externalSheets.map(link => { - const href = link.getAttribute('href'); - - // skip network resources - if (href.match(/^(https?:)?\/\//)) return Promise.resolve(); - - // path on disk - const filename = path.resolve(outputPath, href.replace(/^\//, '')); - - // try to find a matching asset by filename in webpack's output (not yet written to disk) - const asset = compilation.assets[path.relative(outputPath, filename).replace(/^\.\//, '')]; - - // wait for a disk read if we had to go to disk - const promise = asset ? Promise.resolve(asset.source()) : readFile(filename); - return promise.then(sheet => { - // the reduced critical CSS gets injected into a new