Skip to content
Permalink
Browse files

fix: stylesheets in `<link>` are not ignored properly

  • Loading branch information...
sparanoid committed Nov 8, 2016
1 parent 891a526 commit 6bd5f825bbb9898bf84efc12dc4a51b268990e4a
Showing with 18 additions and 8 deletions.
  1. +18 −8 tasks/uncss-inline.js
@@ -27,7 +27,11 @@ module.exports = function ( grunt ) {

var done = this.async();
var options = this.options({
report: 'min'
report: 'min',
// We need to ignore ALL stylesheets (.css in <link>) in order for this
// plugin to work properly. Since we're only focus on inlined stylesheets
// in <style> tags.
ignoreSheets: [/.*/]
});

function processFile ( file, done ) {
@@ -52,13 +56,19 @@ module.exports = function ( grunt ) {
}

var styles = [];
$('style').each(function () {
var style = $(this).html();
if (style) {
styles.push(style);
options.raw = styles.join(' ');
}
});
if ($('style').length) {
$('style').each(function () {
var style = $(this).html();
if (style) {
styles.push(style);
options.raw = styles.join(' ');
}
});
} else {
// This is tricky but it works, if no stylesheets found, just throw a
// blank string to UnCSS to avoid "no stylesheets" error.
options.raw = ' ';
}

try {
uncss( src, options, function ( error, output, report ) {

0 comments on commit 6bd5f82

Please sign in to comment.
You can’t perform that action at this time.