javascript - Gulp.js get filename from .src() -
i'm trying use gulp-proceesshtml (https://github.com/julien/gulp-processhtml) remove unwanted code in build version, problem task requires filename given.
gulp.src('test.html').pipe(processhtml('test.html'));
but can't figure out how work when i'm processing html files in folder
gulp.src('*.html).pipe(processhtml('filename here'));
personally, sounds that's wrong plugin trying accomplish. see below.
however, because it's not clear using for, can able use node-glob process each file one-by-one:
var glob = require('glob') // need event-stream merging streams es = require('event-stream'); gulp.task('mytask', function() { var files = glob.sync('*.html'), streams; streams = files.map(function(file) { // add *base* option if files stored in // multiple subdirectories return gulp.src(file, {base: 'relative/base/path'}) // may need require('path').filename(file) .pipe(processhtml(file)); }); return es.merge.apply(es, streams); }); this create single asynchronous stream out of every file matches initial pattern.
for removing text files, can use gulp-replace, so:
var replace = require('gulp-replace'); gulp.src('*.html') // replaces text between // <!-- remove-this --> , <!-- /remove-this --> .pipe(replace(/<!--\s*remove-this\s*-->[\s\s]*?<!--\s*\/remove-this\s*-->/g, ''));
Comments
Post a Comment