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

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

问题描述

我有一个 gulp rjs 任务,它连接和丑化我所有的自定义 .JS 文件(任何非供应商库).

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).

这是我的树:

 - 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

这是我的 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());

});

推荐答案

快速解答

在 src 上,您始终可以使用!"指定要忽略的文件.

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

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

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.

扩展答案:

摘自 gulp 文档:

gulp.src(globs[, options])

gulp.src(globs[, options])

发出与提供的 glob 或 glob 数组匹配的文件.返回可以通过管道传输到插件的 Vinyl 文件流.

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

glob 指的是 node-glob 语法,也可以是直接的文件路径.

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

因此,查看 node-glob 文档,我们可以看到它使用了 minimatch库进行匹配.

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

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

On minimatch documentation, they point out the following:

如果模式以 !字符,则取反.

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

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

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

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