如何通过Gulp调用ClientJade?

时间:2014-10-01 12:04:03

标签: javascript node.js pug gulp

我被要求帮助在项目中使用ClientJade设置Gulp以支持客户端上的Jade模板使用。

目前有三个模板文件夹,每个模板都运行ClientJade,以生成三个模板JavaScript文件,这些文件在运行时导入和使用。

引入Gulp的目的是能够观察三个模板源文件夹,并在发生更改时重新编译构建文件夹中的相应JavaScript文件。

不幸的是没有gulp ClientJade插件,所以我的下一个想法是通过gulp-shell或gulp-run调用它。我尝试了以下各种版本:

gulp.task('clientTemplates', shell('clientjade src/templates/client/contacts > build/public/templates/contactsTemplates.js'));

gulp.task('clientTemplates', function() {
    run('clientjade src/templates/client/contacts > build/public/templates/contactsTemplates.js').exec();
});

但这总是导致了这个错误:

/Users/helen/src/test/node_modules/clientjade/lib/compile.js:21
  var queue = res.queue(function(file, callback) {
                  ^
TypeError: Object function () {
  if (!(this instanceof Resistance)) {
    return new Resistance();
  }

  this.type = 'series';
  this.flow = [];
} has no method 'queue'
    at compile (/Users/helen/src/test/node_modules/clientjade/lib/compile.js:21:19)

在命令行上调用clientjade src/templates/client/contacts > build/public/templates/contactsTemplates.js直接按预期工作。

我可以从错误消息中看出ClientJade compile.js文件中存在某种“需要”模块的问题(因此尝试在不正确的Object上调用队列方法)但我真的不知所措。如何解决它。

目前我正在使用此处发布的答案(Compile client-side Jade templates using Gulpjs)解决此问题,但这会生成全局模板函数,这与ClientJade不同,后者使模板可用于模板对象。

有没有人知道如何修复我通过gulp-shell或gulp-run调用ClientJade时遇到的错误,或者有关于如何使用gulp运行ClientJade的其他建议?

0 个答案:

没有答案
相关问题