johnpapa / pluralsight-gulp

Starter Code for Pluralsight Course "JavaScript Build Automation with Gulp.js"
http://jpapa.me/gulpps
MIT License
158 stars 262 forks source link

gulp-filter - undefined is not a function when i try to restore #26

Closed HectorLS closed 8 years ago

HectorLS commented 8 years ago

I got this error in the cssFilter.restore() ...

gulp.task('optimize', ['inject'], function() {
  log('Optimizing the javascript, css, html');

  var assets        = useref.assets({searchPath: './'}),
      cssFilter     = filter('**/*.css'),
      templateCache = config.temp + config.templateCache.file;

  return gulp
    .src(config.index)
    .pipe(plumber())
    .pipe(inject(gulp.src(templateCache, {read: false}), {
      starttag: '<!-- inject:templates:js -->'
    }))
    .pipe(assets)
    // Filter down to css
    .pipe(cssFilter)
    // CSS Optimizer
    .pipe(csso())
    // Filter restore
    .pipe(cssFilter.restore())
    .pipe(assets.restore())
    .pipe(useref())
    .pipe(gulp.dest(config.build));
});
[13:20:50] Optimizing the javascript, css, html
[13:20:50] 'optimize' errored after 200 ms
[13:20:50] TypeError: object is not a function
    at Gulp.<anonymous> (/Users/pluralsight-gulp/gulpfile.js:136:21)
    at module.exports (/Users/pluralsight-gulp/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/Users/pluralsight-gulp/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/Users/pluralsight-gulp/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at /Users/pluralsight-gulp/node_modules/gulp/node_modules/orchestrator/index.js:279:18
    at finish (/Users/pluralsight-gulp/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:21:8)
    at /Users/pluralsight-gulp/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:52:4
    at f (/Users/pluralsight-gulp/node_modules/gulp/node_modules/orchestrator/node_modules/end-of-stream/node_modules/once/once.js:17:25)
    at DestroyableTransform.onend (/Users/pluralsight-gulp/node_modules/gulp/node_modules/orchestrator/node_modules/end-of-stream/index.js:31:18)
    at DestroyableTransform.emit (events.js:129:20)
[13:20:50] gulp-inject 1 files into index.html.

But if i modify the cssFilter.restore() and remove that parenthesis, then Plumber talk to me :)

[13:22:34] Optimizing the javascript, css, html
[13:22:34] 'optimize' errored after 200 ms
[13:22:34] Error in plugin 'plumber'
Message:
    Can't pipe to undefined
[13:22:34] gulp-inject 1 files into index.html.

i tried the @annabellor issue-solution but doesn't work

olthof commented 8 years ago

@Tibicenas Did you ever come up with a solution to this problem?

HectorLS commented 8 years ago

No, i had to disable the filter :S still waiting for a hero

olthof commented 8 years ago

I've since found out that the syntax has changed for restore. So for example, it's .pipe(filterName.restore) now, not .pipe(cssFilter.restore())

Give that a go and let me know if it works for you. (If really depends on what version of gulp-filter you're using though)

Reference: https://www.npmjs.com/package/gulp-filter

chsakell commented 8 years ago

That's right, your code should look like this now:

var cssFilter = $.filter('**/*.css', { restore: true });
// code omitted
.pipe(assets)
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore)
// code omitted