gulp-file-includer

A file include plugin for gulp

gulp-file-includer

A file include plugin for gulp 3

First, install gulp-file-includer as a development dependency:

npm install --save-dev gulp-file-includer

Add it to your gulpfile.js:

var gulp = require('gulp')
var fileincluder = require('../index')
 
gulp.task('fileincluder', function() {
  gulp.src(['index.html'])
    .pipe(fileincluder())
    .pipe(gulp.dest('./result/'))
});
 
gulp.task('default', function() {
  gulp.run('fileincluder')
})

index.html

<!DOCTYPE html>
<html>
  <body>
  @@include('./view.html')
  @@include('./var.html', {"name": "haoxin", "age": 12345})
  </body>
</html>

view.html

<h1>view</h1>

var.html

<label>@@name</label>
<label>@@age</label>

and the result is:

<!DOCTYPE html>
<html>
  <body>
  <h1>view</h1>
  <label>haoxin</label>
<label>12345</label>
  </body>
</html>

gulp-file-includer can be called with a config object with these attributes:

  • prefix (defaults to '@@')
  • suffix (defaults to '')
  • basePath (defaults to '') If specified, the default root for the file path.

MIT