Skip to content
This repository has been archived by the owner on Dec 2, 2018. It is now read-only.

Using gulp-uncss with postcss #39

Closed
codedbypaul opened this issue Sep 24, 2015 · 4 comments
Closed

Using gulp-uncss with postcss #39

codedbypaul opened this issue Sep 24, 2015 · 4 comments

Comments

@codedbypaul
Copy link

I'm having an issue getting gulp-uncss playing nicely with postcss. I was originally using gulp-sass which worked fine.

But using postcss I get this error:

/Applications/MAMP/htdocs/wpn-chameleon/addition/node_modules/gulp-uncss/node_modules/uncss/node_modules/bluebird/js/main/async.js:43
        fn = function () { throw arg; };
                                 ^
Error: UnCSS: no stylesheets found
    at process (/Applications/MAMP/htdocs/wpn-chameleon/addition/node_modules/gulp-uncss/node_modules/uncss/src/uncss.js:145:15)

My gulp css task looks like this:

module.exports = function(gulp, plugins, config) {
  return function() {
    return gulp.src(config.development.css.src + '{style,style.ie}.css')
      .pipe(plugins.postcss(processors))
      .pipe(plugins.uncss({
        html: ['./build/development/*.html'],
        ignore: [/(ie7|ie8)/, /\.active/g]
      }))
      .pipe(gulp.dest(config.development.css.dest))
  }
}

Anything obvious as to why it's not working?

@ben-eb
Copy link
Owner

ben-eb commented Sep 24, 2015

Works fine for me:

var postcss = require('gulp-postcss');
var uncss = require('gulp-uncss');
var gulp = require('gulp');

gulp.task('default', function () {
  return gulp.src('./fixture.css')
    .pipe(postcss([ require('postcss-size') ]))
    .pipe(uncss({html: ['./index.html']}))
    .pipe(gulp.dest('out'));
});

fixture.css:

h1, h2 {
  size: 50px;
}

index.html:

<html><body><h1>hello</h1></body></html>

output:

h1 {
  width: 50px;
  height: 50px;
}

@ben-eb ben-eb closed this as completed Sep 24, 2015
@codedbypaul
Copy link
Author

Ok. After changing the source to a single css file it works.

Seems it doesn't like:

return gulp.src(config.development.css.src + {style,style.ie}.css

Turns out it's because the style.ie.css file was empty.

ben-eb added a commit that referenced this issue Sep 24, 2015
@ben-eb
Copy link
Owner

ben-eb commented Sep 24, 2015

OK, no problem. I've added a check that will simply pass through the CSS when the file is empty; as uncss'ing an empty string should return an empty string and not a crash. 😄

It's available since 1.0.4.

@codedbypaul
Copy link
Author

Cool. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants