获取gulp.src()中的当前文件名 [英] Get the current file name in gulp.src()

查看:1863
本文介绍了获取gulp.src()中的当前文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的gulp.js文件中,我将所有HTML文件从示例文件夹流式传输到 build 文件夹中。

创建一个gulp任务并不困难:

  var gulp = require('gulp'); 

gulp.task('examples',function(){
return gulp.src('./ examples / *。html')
.pipe(gulp.dest './build'));
});

但我无法弄清楚如何检索任务中找到(和处理过的)文件名,或者我无法找到正确的插件。

解决方案

我不确定您想如何使用文件名,但其中一个应该有所帮助:


  • 如果您只想查看名称,可以使用 gulp-debug ,其中列出了乙烯基文件的详细信息。插入这个你想要列表的任何地方,如下所示:

      var gulp = require('gulp'),
    debug = require('gulp-debug');
    $ b gulp.task('examples',function(){
    return gulp.src('./ examples / *。html')
    .pipe(debug())
    .pipe(gulp.dest('./ build'));
    });


  • 另一个选项是 gulp-filelog ,这些我没有用过,但听起来很相似(可能会更清晰些) p>


  • 另一个选项是 gulp-文件大小 ,它会输出文件及其大小。

  • 如果您想要更多控制,可以使用如 gulp-tap ,它可让您提供您的自己的功能,并查看管道中的文件。

In my gulp.js file I'm streaming all HTML files from the examples folder into the build folder.

To create the gulp task is not difficult:

var gulp = require('gulp');

gulp.task('examples', function() {
    return gulp.src('./examples/*.html')
        .pipe(gulp.dest('./build'));
});

But I can't figure out how retrieve the file names found (and processed) in the task, or I can't find the right plugin.

解决方案

I'm not sure how you want to use the file names, but one of these should help:

  • If you just want to see the names, you can use something like gulp-debug, which lists the details of the vinyl file. Insert this anywhere you want a list, like so:

    var gulp = require('gulp'),
        debug = require('gulp-debug');
    
    gulp.task('examples', function() {
        return gulp.src('./examples/*.html')
            .pipe(debug())
            .pipe(gulp.dest('./build'));
    });
    

  • Another option is gulp-filelog, which I haven't used, but sounds similar (it might be a bit cleaner).

  • Another options is gulp-filesize, which outputs both the file and it's size.

  • If you want more control, you can use something like gulp-tap, which lets you provide your own function and look at the files in the pipe.

这篇关于获取gulp.src()中的当前文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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