Gulp-wrap: 如何使用动态模板文件?
Gulp-wrap: how to use dynamic template files?
gulp-wrap
是一个优秀的工具,允许我使用模板布局来填充 HTML 文件:
gulp.src('/my/project/**/*.html')
.pipe(wrap({ src: '/my/project/layout.tpl' }))
.pipe(gulp.dest('/my/webapp/'));
现在我的情况是:对于某些 HTML 个文件(例如,名称中包含 'special' 的文件),我需要使用不同的模板布局 special.tpl
。如何融入到上面的工作流程中?我已经搜索过但没有结果。
请帮忙,谢谢。
使用 gulp-switch
解决了问题:
function getLayout(file) {
return file.path.indexOf('special') >= 0 ? 'special' : 'common';
}
return gulp.src(dpwFiles.pages)
.pipe(gulpSwitch(getLayout, {
common: wrap({src: 'layout.tpl' }),
special: wrap({src: 'special.tpl' })
}))
.pipe(gulp.dest('/my/webapp'));
gulp-wrap
是一个优秀的工具,允许我使用模板布局来填充 HTML 文件:
gulp.src('/my/project/**/*.html')
.pipe(wrap({ src: '/my/project/layout.tpl' }))
.pipe(gulp.dest('/my/webapp/'));
现在我的情况是:对于某些 HTML 个文件(例如,名称中包含 'special' 的文件),我需要使用不同的模板布局 special.tpl
。如何融入到上面的工作流程中?我已经搜索过但没有结果。
请帮忙,谢谢。
使用 gulp-switch
解决了问题:
function getLayout(file) {
return file.path.indexOf('special') >= 0 ? 'special' : 'common';
}
return gulp.src(dpwFiles.pages)
.pipe(gulpSwitch(getLayout, {
common: wrap({src: 'layout.tpl' }),
special: wrap({src: 'special.tpl' })
}))
.pipe(gulp.dest('/my/webapp'));