admin管理员组文章数量:1289830
I am looking for a way to insert the file name as a ment to each file in the stream. So after all you'll have a ment line with the file path, in the concatenated destination file.
What it does right now:
pseudocode: concat(file1, file2)
# output:
# contents of file 1
# contents of file 2
What I want to achieve:
pseudocode: concat(add_ments(file1, file2))
# output:
# // file1
# contents of file 1
# // file2
# contents of file 2
I am looking for a way to insert the file name as a ment to each file in the stream. So after all you'll have a ment line with the file path, in the concatenated destination file.
What it does right now:
pseudocode: concat(file1, file2)
# output:
# contents of file 1
# contents of file 2
What I want to achieve:
pseudocode: concat(add_ments(file1, file2))
# output:
# // file1
# contents of file 1
# // file2
# contents of file 2
Share
Improve this question
asked Apr 19, 2014 at 11:26
M KM K
9,4167 gold badges45 silver badges45 bronze badges
2 Answers
Reset to default 9You 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 ment, the file's path
, a newline, and then outputs the same contents as passed in.
I did it with gulp-insert. It has a "transform" function where you are given the file contents, and the Vinyl file object, and you return the new contents. So you can do this:
.pipe(insert.transform(function(contents, file){
return '// ' + file.path + '\n' + contents;
}));
本文标签: javascriptGulpjs concatenation and file namesStack Overflow
版权声明:本文标题:javascript - Gulpjs concatenation and file names - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741487080a2381452.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论