问题
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