问题
I am trying to copy all files EXCEPT js files that are not in the directory 3rd
.
This is what I was doing:
return gulp.src([
'src/**/*',
'!src/**/*.js', // no js files from src
'src/**/3rd/*.js' // make sure to get 3rd party js files though
])
.pipe(gulp.dest('dist'));
However this would not copy ANY js files :(
回答1:
In gulp 3.x globs passed to gulp.src()
are not evaluated in order. That means it is not possible to exclude a set of files and then reinclude a subset of the excluded files.
This will be possible with the upcoming gulp 4.0:
globs passed to gulp.src will be evaluated in order, which means this is possible
gulp.src(['*.js', '!b*.js', 'bad.js']
) (exclude every JS file that starts with ab
exceptbad.js
)
For gulp 3.x there is the gulp-src-ordered-globs package which can be used in place of the regular gulp.src()
:
var gulpSrc = require('gulp-src-ordered-globs');
return gulpSrc([
'src/**/*',
'!src/**/*.js', // no js files from src
'src/**/3rd/*.js' // make sure to get 3rd party js files though
])
.pipe(gulp.dest('dist'));
来源:https://stackoverflow.com/questions/40205232/using-gulp-src-to-include-all-files-except-js-files-not-in-3rd-party-dir