Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix type error while using gulp-filter?

Tags:

gulp-filter

I am mimicking the code from John Papa's outstanding Pluralsight course on Gulp.

When I use the code as shown in John's course:

.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore())

I get an error on the 3rd line of code:

TypeError: Object #<StreamFilter> has no method 'restore'

When I use the code as shown in the readme from gulp-filter

.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore)

I get an error that it can't pipe to undefined.

Based on what I can find online, both of these patterns are working for others. Any clues as to why this might be happening?

Here is the whole task, if that helps and the console logging indicates that everything if fine until the filter restore call.

Here is the entire task if that helps:

gulp.task('build-dist', ['inject', 'templatecache'], function() {
    log('Building the distribution files in the /dist folder');

    var assets = $.useref.assets({searchPath: './'});
    var templateCache = config.temp + config.templateCache.file;
    var jsFilter = $.filter('**/*.js');

    return gulp
        .src(config.index)
        .pipe($.plumber({errorHandler: onError}))
        .pipe($.inject(gulp.src(templateCache, {read: false}), {
            starttag: '<!-- inject:templates:js -->'
        }))
        .pipe(assets)
        .pipe(jsFilter)
        .pipe($.uglify())
        .pipe(jsFilter.restore())
        .pipe(assets.restore())
        .pipe($.useref())
        .pipe(gulp.dest(config.dist));
});
like image 897
pthalacker Avatar asked Oct 02 '15 19:10

pthalacker


1 Answers

The way restore works has changed between the 2.x and 3.x release of gulp-filter.

It seems you're using the 3.x branch, so in order to use restore you'll have to set the restore option to true when defining the filter:

var jsFilter = $.filter('**/*.js', {restore: true});

Then you'll be able to do

.pipe(jsFilter.restore)

For more information, check out this section of the documentation for the latest version of gulp-filter:

https://github.com/sindresorhus/gulp-filter/tree/v3.0.1#restoring-filtered-files

like image 178
Andrei Avram Avatar answered Oct 06 '22 08:10

Andrei Avram