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
工欲善其事 必先利其器