You can use the gulp-wrap
plugin to prepend the file name before concatenating:
var wrap = require('gulp-wrap');
// in your task...
return gulp.src('src/**/*.js')
.pipe(wrap('//<%= file.path %>\n<%= contents %>'))
.pipe(concat('output.js'))
.pipe(gulp.dest('build'))
The wrap plugin allows you to wrap the contents of an item in the stream with a lodash (or underscore) template. It provides contents
and file.*
properties automatically.
The template I created is very simple: it outputs two slashes for the comment, the file's path
, a newline, and then outputs the same contents as passed in.