How can I invoke ClientJade through Gulp?

*爱你&永不变心* 提交于 2020-01-25 04:26:09

问题


I have been asked to help set up Gulp in a project using ClientJade to support Jade template usage on the client.

Currently there are three folders of templates, and ClientJade is run on each to produce three template JavaScript files which are imported and used at run time.

The goal of introducing Gulp is to be able to watch the three template source folders and recompile the appropriate JavaScript files in the build folder when a change occurs.

Unfortunately there is no gulp ClientJade plugin, so my next idea was to invoke it through gulp-shell or gulp-run. I tried various versions of the following:

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();
});

But that always led to this error:

/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)

Calling clientjade src/templates/client/contacts > build/public/templates/contactsTemplates.js on the command line directly worked as expected.

I can tell from the error message that there is some kind of problem 'requiring' modules in the ClientJade compile.js file (thus the attempted invocation of the queue method on the incorrect Object) but I am really at a loss as to how to fix it.

For now I am working around the issue using an answer posted here (Compile client-side Jade templates using Gulpjs) but this produces global template functions, unlike ClientJade which makes templates available off a template object.

Does anyone have an idea how to fix the error I was experiencing invoking ClientJade through gulp-shell or gulp-run, or have another suggestion as to how to run ClientJade with gulp?

来源:https://stackoverflow.com/questions/26140953/how-can-i-invoke-clientjade-through-gulp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!