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

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

问题描述

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

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

创建 gulp 任务并不难:

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:

  • 如果您只想查看名称,可以使用 gulp-debug,其中列出了黑胶文件的详细信息.将其插入您想要列表的任何位置,如下所示:

  • 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'));
});

  • 另一个选项是 gulp-filelog,我没有'未使用,但听起来相似(可能更干净一些).

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

    另一个选项是 gulp-filesize,它同时输出文件及其大小.

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

    如果你想要更多的控制,你可以使用类似 gulp-tap,它允许您提供自己的函数并查看管道中的文件.

    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天全站免登陆