cgross / gulp-dom-src

Create a gulp stream from script, link, or any set of tags in an HTML file.
MIT License
41 stars 8 forks source link

Adding duplex feature #3

Closed psalaets closed 9 years ago

psalaets commented 9 years ago

Here's my attempt at making gulp-dom-src writeable for #2.

I added a "duplex" function to domSrc which is where the write/read stream comes from. The existing cheerio code was reusable.

After scanning the html for script/style references, it reads them one by one using vinyl-file with async and sends them down the stream.

A really basic usage example:

var gulp = require('gulp');
var domSrc = require('gulp-dom-src');
var concat = require('gulp-concat');

gulp.task('go', function() {
  return gulp.src('index.html')
    .pipe(domSrc.duplex({
      selector: 'script',
      attribute: 'src'
    }))
    .pipe(concat('bundle.js'))
    .pipe(gulp.dest('build/'));
});
cgross commented 9 years ago

Great pull request. Thanks!