从Gulp任务中排除文件/目录 [英] Excluding files/directories from Gulp task

查看:578
本文介绍了从Gulp任务中排除文件/目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gulp rjs任务,它将所有自定义的.JS文件(任何非供应商库)连接起来并使其uglify。



我想要做的是排除



我的树:

   - 应用程序
- 资源
- js
main.js
- 供应商
- jquery
- modernzr
- 角度
- 控制器
- 控制器1
- 控制器2
- 控制器3
- 指令
- 指令1
- 指令2
- directives3
- 小工具
- 小工具1
- 小工具2
- 小工具3
- 小工具4
- 模块
- 模块1
- modules2
- modules3
- modules4

这里是我的gulp.js

  dir = {
app:'application',
dest:'dest',
};

config = {
src:{
js:dir.app +'/ resources / js'
},
dest:{
js:dir.dest +'/ resources / js'
}
};
$ b gulp.task('rjs',function(){

rjs({
baseUrl:config.src.js,
out:' main.js',
name:'main',
mainConfigFile:config.src.js +'/main.js',
exclude:['jquery','angular'] $ ({mangle:false,outSourceMap:true,compress:{drop_console:true}}):gutil.noop())
.pipe(gulp。b $ b})
.pipe(prod?uglify dest(config.dest.js))
.pipe(filesize())
.pipe(dev?connect.reload():gutil.noop());

});


解决方案

快速回答 p>

在src中,您始终可以使用!指定要忽略的文件。



示例(要排除所有* .min.js文件在您的js文件夹和子文件夹中:

  gulp.src(['js / ** / *。 js','!js / ** / * .min.js'])

你可以做它也适用于个人文件。



扩展答案:
$ b

从gulp文档中提取:


gulp.src(globs [,options])



发出匹配提供的glob或一个globs数组的文件。乙烯基文件,可以传送到插件。

glob指的是节点glob语法,或者它可以是一个直接的文件路径。



所以,期待node-glob文档,我们可以看到它使用minimatch库进行匹配。



minimatch文档上,他们指出以下内容:


如果模式以!字符,那么它是否定的。


这就是为什么使用!符号将从一个吞咽任务中排除文件/目录

I have a gulp rjs task that concatenates and uglifies all my custom .JS files (any non vendor libraries).

What i am trying to do, is exclude some files/directories from this task (controllers and directives).

Heres my tree:

 - application
    - resources
      - js
        main.js
        - vendor
            - jquery
            - modernzr
            - angular
        - controllers
            - controller1
            - controller2
            - controller3
        - directives
            - directives1
            - directives2
            - directives3
        - widgets
            - widget1
            - widget2
            - widget3
            - widget4
        - modules
            - modules1
            - modules2
            - modules3
            - modules4

Here my gulp.js

dir = {
    app:        'application',
    dest:       'dest',
};

config = {
    src: {
        js: dir.app + '/resources/js'
    },
    dest: {
        js: dir.dest + '/resources/js'
    }
};

gulp.task('rjs', function() {

      rjs({
            baseUrl: config.src.js,
            out: 'main.js',
            name: 'main',
            mainConfigFile: config.src.js + '/main.js',
            exclude: [ 'jquery', 'angular']         
        })
        .pipe(prod ? uglify({ mangle: false, outSourceMap: true, compress: { drop_console: true } }) : gutil.noop())
        .pipe(gulp.dest(config.dest.js))
        .pipe(filesize())
        .pipe(dev ? connect.reload() : gutil.noop());

});

解决方案

Quick answer

On src, you can always specify files to ignore using "!".

Example (you want to exclude all *.min.js files on your js folder and subfolder:

gulp.src(['js/**/*.js', '!js/**/*.min.js'])

You can do it as well for individual files.

Expanded answer:

Extracted from gulp documentation:

gulp.src(globs[, options])

Emits files matching provided glob or an array of globs. Returns a stream of Vinyl files that can be piped to plugins.

glob refers to node-glob syntax or it can be a direct file path.

So, looking to node-glob documentation we can see that it uses the minimatch library to do its matching.

On minimatch documentation, they point out the following:

if the pattern starts with a ! character, then it is negated.

And that is why using ! symbol will exclude files / directories from a gulp task

这篇关于从Gulp任务中排除文件/目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆