Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the current file name in gulp.src()

Tags:

gulp

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.

like image 762
dkastl Avatar asked Feb 16 '14 03:02

dkastl


People also ask

What does gulp src do?

The src() and dest() methods are exposed by gulp to interact with files on your computer. src() is given a glob to read from the file system and produces a Node stream. It locates all matching files and reads them into memory to pass through the stream.

What was used by the gulp files?

Gulp is a task runner that uses Node. js as a platform. Gulp purely uses the JavaScript code and helps to run front-end tasks and large-scale web applications. It builds system automated tasks like CSS and HTML minification, concatenating library files, and compiling the SASS files.


1 Answers

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.

like image 196
OverZealous Avatar answered Oct 05 '22 21:10

OverZealous