The first usage example is incorrect and gives the wrong impression about how gulp-filter matches files.
See original GitHub issueI’m referring to this
var gulp = require('gulp');
var jscs = require('gulp-jscs');
var gulpFilter = require('gulp-filter');
gulp.task('default', function () {
// create filter instance inside task function
var filter = gulpFilter(['*', '!src/vendor']);
return gulp.src('src/*.js')
// filter a subset of the files
.pipe(filter)
// run them through a plugin
.pipe(jscs())
.pipe(gulp.dest('dist'));
});
The intent seems to process everything in src
but to exclude the files in src/vendor
. Problems:
- The filter does no work because
src/*.js
won’t go into subdirectories in the first place. You could remove the filter and you’d still not get anything fromsrc/vendor
intodest
. - If we amend to
src/**/*.js
then this pattern will cover every.js
file insrc
, including subdirectories but the filter still gives the wrong impression. It does the work of excluding files insrc/vendor
not because of!src/vendor
but because of*
, which matches only files that are not in a subdirectory. You could reduce the filter togulpFilter('*')
and it would still excludesrc/vendor
and everything in it. - If we amend the filter so that we have
**
instead of*
, then the filter no longer works because!src/vendor
does not match anything. Why? Becausegulp-filter
matches against the file’s relative path.
Ultimately, the code I see doing what the example seems to be illustrating should be:
var gulp = require('gulp');
var jscs = require('gulp-jscs');
var gulpFilter = require('gulp-filter');
gulp.task('default', function () {
// create filter instance inside task function
var filter = gulpFilter(['**', '!vendor/**']);
return gulp.src('src/**/*.js')
// filter a subset of the files
.pipe(filter)
// run them through a plugin
.pipe(jscs())
.pipe(gulp.dest('dist'));
});
The examples based off of this one should also be fixed.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How can I stop ASP.NET Core 2.0 MVC minification from ...
As you may deduct from the name, the gulp-filter plugin is what we will use to exclude files from the minification process.
Read more >Getting Started with Gulp.js - Semaphore Tutorial
Learn how to set up and use Gulp.js, a task runner for Node.js based on Node streams. ... Create a sample Sass file...
Read more >PTE Reading Practice Class | Grammar Rules and Tricks
PTE Reading Practice Class✓In this video, our PTE Expert Ripan shares some important Tips to solve PTE Reading Blanks, Reading & Writing ...
Read more >Release notes | U.S. Web Design System (USWDS) - Digital.gov
Tooltip now initializes on first interaction and checks if it has been ... Starting in USWDS 3.0, projects will use settings files that...
Read more >license_scanning (#2758) · Jobs · osm / NG-UI · GitLab
n\n## Installing\n\nIf you use NPM, `npm install d3-transition`. ... If multiple typenames are specified, the first matching listener is ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The “Usage” section on the npm page still shows the example with a single asterisk: https://www.npmjs.com/package/gulp-filter#filter-only
This was fixed in https://github.com/leocaseiro/gulp-filter/commit/922496e5507c39ed44f181f209b1e3866c71ae24.