Closed jcalvor closed 8 years ago
Use gulp-header?
Hi there!, I saw gulp-header but this adds more work at the end of the day we usually need something fast and that it can be optional like this idea. This specific feature lets you add a new line on top of every file with the name of that file. It takes the files names without the need of setting variables like gulp-header does for every file, the same concat pluggin provides the variable. This helps to keep track of big data files and to track information/bugs from that big file without the time consuming of the other plugging. You just add a group of files and concat them and that's it.
var concat = require('gulp-concat');
gulp.task('scripts', function() { return gulp.src(['./lib/.js']) .pipe(concat('bundle.css', {addHeaders: function(fileName, src) { return '/* '+fileName+' **/\n' + src; }})) .pipe(gulp.dest('./dist')); });
here is the beauty of it, you can set the option to add the new line with the name of every file that its been concatenating and you can add this with a comment as a comment for any language: js, css, sql or anything as long as you surround the comment with the proper delimiters.
At the end you only have a 3 line extra code in the pluggin that is optional: if (opt.addHeaders){ file.contents = new Buffer(opt.addHeaders(file.relative, file.contents)); }
more that adding a "simple header", it is identifying all the files in one. I guess if you want you can change the name, because I think it is more powerful than just adding a "header". Does that make sense? I hope you like it. I think your work is really good.
You can use templating in your header - set the header to // ${file.name}
and it will add the comment to the top of each file, then pipe to concat. gulp has a philosophy that plugins do one thing well, so this feature won't end up in concat.
'addHeader' lines with the name of each file to identify each file in the 'bundle' final file.