1

I started loving gulp but I've been having too many cryptic errors that are very hard to find and at the end I'm working for my gulpfile.js instead of doing my job.

Anyway, I tried gulp-uncss before, outside gulp-useref and therefore outside gulp-if, but my gulpfile.js ended up too bulky and unreadable. Now it's readable but it doesn't work. Hurray.

var p = require('gulp-load-plugins')();

gulp.task('html', function () {
    var assets = p.useref.assets();

    gulp.src('*.html')
        .pipe(assets)
        .pipe(p.if('*.js', p.uglify()))
        .pipe(p.if('*.css', p.uncss()))
        .pipe(assets.restore())
        .pipe(p.useref())
        .pipe(gulp.dest(build_folder))
        .pipe(p.size());
});

That generates this:

[12:47:53] /long/path/web $ gulp html
[12:48:06] Using gulpfile /long/path/web/gulpfile.js
[12:48:06] Starting 'html'...
[12:48:07] 'html' errored after 507 ms
[12:48:07] TypeError: Cannot set property 'ignoreSheets' of undefined
    at Object.module.exports (/long/path/web/node_modules/gulp-uncss/index.js:14:26)
    at Gulp.<anonymous> (/long/path/web/gulpfile.js:45:31)
    at module.exports (/long/path/web/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/long/path/web/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/long/path/web/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/long/path/web/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
    at /usr/local/lib/node_modules/gulp/bin/gulp.js:129:20
    at process._tickCallback (node.js:355:11)
    at Function.Module.runMain (module.js:503:11)
    at startup (node.js:129:16)
    at node.js:814:3
[12:48:12] /long/path/web $ 

Uncss was crucial to my workflow and I can't crack what's going wrong here. Any clue?

EDIT: This is what's in /long/path/web/node_modules/gulp-uncss/index.js until line 14

'use strict';

var uncss       = require('uncss'),
    gutil       = require('gulp-util'),
    assign      = require('object-assign'),
    transform   = require('stream').Transform,

    PLUGIN_NAME = 'gulp-uncss';

module.exports = function(options) {
    var stream = new transform({ objectMode: true });

    // Ignore stylesheets in the HTML files; only use those from the stream
    options.ignoreSheets = [/\s*/];
Neithan Max
  • 11,004
  • 5
  • 40
  • 58

1 Answers1

1

Well, your excerpt of gulp-uncss/index.js states, that it can not handle an undefined options parameter - which it is not in you gulpfile:

.pipe(p.if('*.css',
  p.uncss({
    html: [ '*.html' ] // html files to check for styles to keep
  })
))

The doc also states, that html is an required option attribute: npmjs.com/package/gulp-uncss#html

Type: Array|String Required value.

An array which can contain an array of files relative to your gulpfile.js, and which can also contain URLs. Note that if you are to pass URLs here, then the task will take much longer to complete. If you want to pass some HTML directly into the task instead, you can specify it here as a string.

Community
  • 1
  • 1
naeramarth7
  • 6,030
  • 1
  • 22
  • 26
  • It must have been recent updates, since the examples I've read are just like that. Could you provide a working fix? – Neithan Max Apr 13 '15 at 23:59