This is the Gulp plugin which extracts only the part specified by CSS selector. (CSSセレクターで指定した部分のみを取り出すGulpプラグインです。)
npm install --save-dev gulp-html-takeout
gulpfile.js
var gulp = require("gulp");
var takeout = require("gulp-html-takeout");
var concat = require("gulp-concat");
gulp.task('default',function(){
return gulp.src(['sample/*.html'])
.pipe(takeout('h1'))
.pipe(concat('bundle.html'))
.pipe(gulp.dest('dist/'));
});
sample/hello.html
<h1>Hello</h1>
sample/world.html
<h1>World</h1>
dist/bundle.html
Hello
World
Set CSS Seletor. If not specified, "body" is the default.
// == "body"
.pipe(takeout())
// HTML element
.pipe(takeout("html"))
.pipe(takeout("head"))
.pipe(takeout("h1"))
//Class and ID
.pipe(takeout(".foo"))
.pipe(takeout("#bar"))
If more than one HTML Element is applicable
gulp.task('default',function(){
return gulp.src(['sample/*.html'])
.pipe(takeout('h1'))
.pipe(concat('bundle.html'))
.pipe(gulp.dest('dist/'));
});
sample/foo.html
<h1>Hello</h1>
<h1>World</h1>
dist/bundle.html
HelloWorld