gulp-query-selector

Selects DOM nodes from HTML in Node.js streams.

Usage no npm install needed!

<script type="module">
  import gulpQuerySelector from 'https://cdn.skypack.dev/gulp-query-selector';
</script>

README

gulp-query-selector

Build Status Dependency Status devDependency Status NPM version

Selects DOM nodes from Node.js streams and packs selected code into separated streams.

Usage

First, install gulp-query-selector as a development dependency:

npm install --save-dev gulp-query-selector

Then, add it to your gulpfile.js:

var querySelector = require("gulp-query-selector");
var inject = require("gulp-inject");

gulp.task("make-html", function(){
  var partials = gulp.src("pages/*.html")
    .pipe(querySelector("body > *"))
    .pipe(querySelector.groupBySource());
  return gulp.src("index.html")
    .pipe(inject(partials), {
      starttag: '<!-- inject:partials -->',
      transform: function (filePath, file) { return file.contents.toString('utf8'); }
    })
    .pipe(gulp.dest("./dist"));
});

Above example is pretty complicated, but it's the simplest one I've been able to come up with. It selects contents of <body> elements from all HTML files found in pages forlder, and then injects these contents to another HTML code using gulp-inject plugin.

License

Copyright © 2015 - 2019 Maciej ChaƂapuk. Released under MIT License.