critters-webpack-plugin
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -109,7 +109,6 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var outputPath, document, styles; | ||
var outputPath, document, externalSheets, styles; | ||
outputPath = compiler.options.output.path; | ||
document = createDocument(html); | ||
if (this.options.external !== false) { | ||
var externalSheets; | ||
externalSheets = [].slice.call(document.querySelectorAll('link[rel="stylesheet"]')); | ||
@@ -142,3 +141,4 @@ return Promise.all(externalSheets.map(function (link) { return this$1.embedLinkedStylesheet(link, compilation, outputPath); })).then((function ($await_4) { | ||
return new Promise((function ($return, $error) { | ||
var href, media, document, preloadMode, filename, asset, sheet, cssLoaderPreamble, lazy, style, noscriptFallback; | ||
var href, media, document, preloadMode, filename, asset, sheet, lazy, style, script, js, bodyLink, noscript, noscriptLink; | ||
var cssLoaderPreamble, noscriptFallback; | ||
href = link.getAttribute('href'); | ||
@@ -177,5 +177,3 @@ media = link.getAttribute('media'); | ||
if (preloadMode === 'js' || preloadMode === 'js-lazy') { | ||
var script; | ||
script = document.createElement('script'); | ||
var js; | ||
js = cssLoaderPreamble + "$loadcss(" + (JSON.stringify(href)) + (lazy ? ',' + JSON.stringify(media || 'all') : '') + ")"; | ||
@@ -196,3 +194,2 @@ script.appendChild(document.createTextNode(js)); | ||
} else { | ||
var bodyLink; | ||
bodyLink = document.createElement('link'); | ||
@@ -207,5 +204,3 @@ bodyLink.setAttribute('rel', 'stylesheet'); | ||
if (this.options.noscriptFallback !== false && noscriptFallback) { | ||
var noscript; | ||
noscript = document.createElement('noscript'); | ||
var noscriptLink; | ||
noscriptLink = document.createElement('link'); | ||
@@ -247,3 +242,3 @@ noscriptLink.setAttribute('rel', 'stylesheet'); | ||
rule.selectors = rule.selectors.filter(function (sel) { | ||
sel = sel.replace(/::?(?:[a-z-]+)([.[#~&^:*]|\s|\n|$)/gi, '$1').trim(); | ||
sel = sel.replace(/::?[a-z-]+\s*{/gi, '{').trim(); | ||
try { | ||
@@ -262,3 +257,3 @@ return document.querySelector(sel) != null; | ||
var decl = rule.declarations[i]; | ||
if (decl.property && decl.property.match(/\bfont\b/i)) { | ||
if (decl.property && decl.property.match(/\bfont(-family)?\b/i)) { | ||
criticalFonts += ' ' + decl.value; | ||
@@ -285,3 +280,3 @@ } | ||
var shouldPreloadFonts = options.fonts === true || options.preloadFonts === true; | ||
var shouldInlineFonts = options.fonts !== false || options.inlineFonts === true; | ||
var shouldInlineFonts = options.fonts !== false && options.inlineFonts === true; | ||
var preloadedFonts = []; | ||
@@ -288,0 +283,0 @@ walkStyleRules(ast, function (rule) { |
{ | ||
"name": "critters-webpack-plugin", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Webpack plugin to inline critical CSS and lazy-load the rest.", | ||
@@ -5,0 +5,0 @@ "main": "dist/critters.js", |
@@ -300,3 +300,3 @@ /** | ||
// This means any selector for a pseudo-element or having a pseudo-class will be inlined if the rest of the selector matches. | ||
sel = sel.replace(/::?(?:[a-z-]+)([.[#~&^:*]|\s|\n|$)/gi, '$1').trim(); | ||
sel = sel.replace(/::?[a-z-]+\s*{/gi, '{').trim(); | ||
try { | ||
@@ -319,3 +319,3 @@ return document.querySelector(sel) != null; | ||
// detect used fonts | ||
if (decl.property && decl.property.match(/\bfont\b/i)) { | ||
if (decl.property && decl.property.match(/\bfont(-family)?\b/i)) { | ||
criticalFonts += ' ' + decl.value; | ||
@@ -352,3 +352,3 @@ } | ||
const shouldPreloadFonts = options.fonts === true || options.preloadFonts === true; | ||
const shouldInlineFonts = options.fonts !== false || options.inlineFonts === true; | ||
const shouldInlineFonts = options.fonts !== false && options.inlineFonts === true; | ||
@@ -355,0 +355,0 @@ const preloadedFonts = []; |
Sorry, the diff of this file is not supported yet
103173
1082