我在服务器端使用 express 和 node 并将把手用作模板引擎。现在从gulp-compile-handlebars 的官方文档中我了解了车把模板的预编译技术,我正在做如下 -
const handlebars = require('gulp-compile-handlebars');
const rename = require('gulp-rename');
gulp.task('compile-handlebars', function () {
var templateData = {
data: 'Kaanon'
},
options = {
batch : ['./views/partials'],
helpers : {
capitals : function(str){
return str.toUpperCase();
}
}
}
return gulp.src('views/home.handlebars')
.pipe(handlebars(templateData, options))
.pipe(rename('home.html'))
.pipe(gulp.dest('build'));
});
但这允许我一个一个地预编译车把模板,而我想要一个进程,它将在该进程本身中将所有文件编译为 html。
例如 SASS 编译并转换为 Css 文件我正在这样做,
const sass = require('gulp-sass');
gulp.task('styles', function() {
gulp.src('sass/*.scss')
.pipe(sass(compile_config).on('error', sass.logError))
.pipe(gulp.dest('./assets/css/'))
});
这会将所有 sass 文件转换为相应的 css 文件。
我希望我的车把模板也有类似的东西。
附上我的目录结构以便更好地理解,