Using gulp.src() to include all files EXCEPT js files NOT in 3rd party dir

喜你入骨 提交于 2019-12-13 18:12:58

问题


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 a b except bad.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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!