Gulp plugin to split HTML files into multiple output files using HTML comments.
npm install gulp-htmlsplitnpm install gulp-htmlsplit --save-dev
js
var htmlsplit = require('gulp-htmlsplit');
// ...
gulp.task('foo', function() {
gulp.src('./*.html')
.pipe(htmlsplit())
.pipe(gulp.dest('build'));
})
`
$3
The plugin will look for comments of the form:
Everything following one of these comments will be piped to a file named filename.ext,
until another split comment is encountered, or the file ends.
If the HTML file does not begin with a split comment, the contents will be discarded
until the first comment is encountered. If no split comment is encountered,
the file will be left in the pipeline unchanged.
The resulting files can then be piped to other steps in the task or written out.
`html
Example
My header here
My content here
`
If the filename is the special string stop, all content will be discarded until
the next split comment is encountered. For example, to extract just the header
and footer elements into separate files:
`html
Example
My header here
My content here
`
An alternate stop string can be specified in the options:
`js
gulp.task('foo', function() {
gulp.src('./*.html')
.pipe(htmlsplit({ stop: 'end-here' }))
.pipe(gulp.dest('build'));
})
``