robrich / gulp-ignore

plugin for gulp to ignore files in the stream based on file characteristics
MIT License
121 stars 10 forks source link

Gulp ignore, not ignoring. #6

Closed chopfitzroy closed 9 years ago

chopfitzroy commented 9 years ago

In my Gulpfile I have the following Task:

// HTML
gulp.task('html', function() {
  return  gulp.src(path.join(config.src, '/**/*.html'))
    .pipe(ignore.exclude(config.include))
    .pipe(fileinclude())
    .pipe(connect.reload())
    .pipe(gulp.dest(config.dist))
});

I am using gulp-ignore to exclude the includes directory however it is not working and includes all ways ends up in the dist folder.

I assume I have set the variable right:

var config = {
   include: 'src/includes' // Includes Directory
};

so this is the line I am having trouble with:

.pipe(ignore.exclude(config.include))

Anyone come across something similar?

Full Gulpfile.

mouryaamit commented 9 years ago

@robrich Nothing working. @CrashyBang did you got any solution.

Jakobud commented 9 years ago

It's not working at all for me either. I'm not sure what I could be doing wrong. It seems like it should be very straightforward. Here is my code:

return gulp.src('./public/**/*')
        .pipe(gulpIgnore.exclude('./public/favicon.ico'))
        .pipe(gulp.dest('./build'));

This should be copying all of the public directory to the build directory but it should be excluding the favicon.ico file. But it does not work at all. What am I doing wrong?

markfarrall commented 9 years ago

I can now see the key point in the documentation, but it took a while to sink in. You need to use the vinyl-fs object for your conditions.

So for file name comparison you need to use the path item of the vinyl-fs object. Taking the example from the last comment something like this should work:

return gulp.src('./public/**/*')
    .pipe(gulpIgnore.exclude(function(file) {       
        if (file.path.indexOf('public/favicon.ico') > 0)
            return true;
    }))
    .pipe(gulp.dest('./build'));
stiofand commented 9 years ago

Not working here, nothing being excluded. I want to exclude a particular folder from the src, not a single file, so the vinyl object is no good to me

robrich commented 9 years ago

Stephen,

Do you have an example gulpfile on GitHub or pastebin that shows this behavior?

stiofand commented 9 years ago

Not any longer, I went with another solution

emilsoman commented 9 years ago

@stevematdavies what solution did you go with ?

emilsoman commented 9 years ago

As the README says, you can pass in anything that works with gulp-match, so it should work if you pass in something like this : .pipe(gulpIgnore.exclude(/public\/favicon\.ico/))

juhamust commented 9 years ago

Same issue here. End up using gulp-filter: https://www.npmjs.com/package/gulp-filter (which also required few tries and errors, though)

robrich commented 9 years ago

Globs are pretty finiky. @CrashyBang: change your exclude glob to 'src/includes/**' or 'src/includes/**/*.html' to ensure it matches. As you wrote it, the glob believes inclues is a file, not a folder. Want to PR to improve the glob docs?