index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Gulp-html-import Example</title>
</head>
<body>
@import "header.html"
<p>Hello World</p>
@import "footer.html"
</body>
</html>
header.html
<h1>I am the header</h1>
footer.html
<h1>I am the footer</h1>
gulpfile.js
var gulp = require('gulp');
var gulpImport = require('gulp-html-import');
gulp.task('import', function () {
gulp.src('./demo/index.html')
.pipe(gulpImport('./demo/components/'))
.pipe(gulp.dest('dist'));
})
最终合成的index.js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Gulp-html-import Example</title>
</head>
<body>
<h1>I am the header</h1>
<p>Hello World</p>
<h1>I am the footer</h1>
</body>
</html>