gulp(五)插件gulp-swig

npm install --save-dev gulp-swig

/*
  Get data via JSON file, keyed on filename.
*/
var swig = require('gulp-swig');
var data = require('gulp-data');
 
var getJsonData = function(file) {
  return require('./examples/' + path.basename(file.path) + '.json');
};
 
gulp.task('json-test', function() {
  return gulp.src('./examples/test1.html')
    .pipe(data(getJsonData))
    .pipe(swig())
    .pipe(gulp.dest('build'));
});
var swig = require('gulp-swig');
var opts = {
  data: {
    headline: "Welcome"
  }
};
gulp.task('templates', function() {
  gulp.src('./lib/*.html')
    .pipe(swig(opts))
    .pipe(gulp.dest('./dist/'))
});
var swig = require('gulp-swig');
var opts = {
  load_json: true
};
gulp.task('templates', function() {
  gulp.src('./lib/*.html')
    .pipe(swig(opts))
    .pipe(gulp.dest('./dist/'))
});
var swig = require('gulp-swig');
var opts = {
  load_json: true,
  data: {
    headline: "Welcome"
  }
};
gulp.task('templates', function() {
  gulp.src('./lib/*.html')
    .pipe(swig(opts))
    .pipe(gulp.dest('./dist/'))
});

 

参考:

https://www.npmjs.com/package/gulp-swig

https://www.jscss.cc/2016/10/22/gulp-swig.html

posted @ 2018-01-03 14:41  我将枕中记忆抹去任岁月浮光掠影  阅读(567)  评论(0编辑  收藏  举报