gulp-filter is filtering everything.
I'm trying to use gulp-filter to exclude a single file from gulp-uglify:
var uglify = require('gulp-uglify');
var filter = require('gulp-filter');
var paths = {
css: 'src/*.css',
html: 'src/*.html',
js: 'src/*.js'
};
gulp.task('js', function() {
// Create a filter for the ToC options file. We don't want to minify that.
var f = filter(['*', '!src/ToCOptions.js'], {"restore": true});
return gulp.src(paths.js)
.pipe(f)
.pipe(uglify())
.pipe(f.restore)
.pipe(gulp.dest('js'));
});
I've read gulp-filter filters out all files, which seems to be the same problem, but the accepted answer doesn't work for me.
I've tried several variations on the filter, including:
var f = filter(['*', '!ToCOptions.js'], {"restore": true});
var f = filter('!ToCOptions.js', {"restore": true});
var f = filter('!src/ToCOptions.js', {"restore": true});
var f = filter('src/ToCOptions.js', {"restore": true});
var f = filter(['*', 'src/ToCOptions.js'], {"restore": true});
var f = filter(['*', '!/src/ToCOptions.js'], {"restore": true});
var f = filter(['*', '!/ToCOptions.js'], {"restore": true});
What am I doing wrong?
Apparently, this is an error in the documentation that is explained in issue #55 at the Github repository.
The solution in my case is this:
var f = filter(['**', '!src/ToCOptions.js'], {'restore': true});
As the author of the issue explains, a single asterisk only matches files that are not in subdirectories. All of the files for this task are in a subdirectory, so the first pattern didn't match anything and the second pattern didn't have any results to subtract from.
To understand **
, I had to use man bash
on a Linux system and search for globstar since the node-glob documentation makes reference to the Bash implementation:
globstar
If set, the pattern ** used in a pathname expansion context will
match all files and zero or more directories and subdirectories. If the
pattern is followed by a /, only directories and subdirectories match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With