I am using Gulp as a build process and I have recently run into some problems with page-specific files injection (through gulp-inject fyi).
Some context: I am grabbing all the HTML files, and then go over them one at a time so I can use their filename to include specific files into the glob collection, for example for index.html
I have:
[
'export/assets/js/libs/jquery*.js', // jQuery first
'export/assets/js/libs/*.js', // Followed by all the libs
'export/assets/js/*.js', // Followed by any other js file
'!export/assets/js/view-*.js', // Excluding all view-* files [see note]
'!export/assets/**/_*.js', // Excluding underscore prefixed files
'!export/assets/js/ie*.js', // Excluding all IE libs
'export/assets/js/view-index*.js' // Including page specific file
]
[note] There might be more page-specific files, eg. view-profile.js
or view-contact.js
but in this iteration, only view-index.js
can be included.
The above collection is then gulp.src()
'd and processed, only, view-index.js
never makes it into the stream..
EDIT:
I accepted the answer below because it pointed out that what I had wasn't going to suffice in achieving my goal. I found a work-around where I pass in export/assets/js/**/*.js
and filter out what I don't need through gulp-ignore.
Since minimatch doesn't explicitly support negate globbing patterns, most libraries implement something like "collect all the negations, now call minimatch on the rest, now apply all the negations." See https://github.com/wearefractal/glob-stream/blob/master/index.js#L28 (Note glob-stream is used by vinyl-fs which is exposed as gulp's src.)