0

我正在尝试使用 gulp 作为我的 rendr 应用程序的编译器,但我遇到了问题

500 TypeError: template is not a function
   at module.exports.Backbone.View.extend.getInnerHtml (/home/longjeongs/thinksquareio.github.io/node_modules/rendr/shared/base/view.js:191:12)
   at module.exports.Backbone.View.extend.getHtml (/home/longjeongs/thinksquareio.github.io/node_modules/rendr/shared/base/view.js:198:21)
   at ViewEngine.getViewHtml (/home/longjeongs/thinksquareio.github.io/node_modules/rendr/server/viewEngine.js:75:15)
   at ViewEngine.render (/home/longjeongs/thinksquareio.github.io/node_modules/rendr/server/viewEngine.js:22:16)
   at View.render (/home/longjeongs/thinksquareio.github.io/node_modules/express/lib/view.js:126:8)
   at tryRender (/home/longjeongs/thinksquareio.github.io/node_modules/express/lib/application.js:639:10)
   at EventEmitter.render (/home/longjeongs/thinksquareio.github.io/node_modules/express/lib/application.js:591:3)
   at ServerResponse.render (/home/longjeongs/thinksquareio.github.io/node_modules/express/lib/response.js:961:7)
   at /home/longjeongs/thinksquareio.github.io/node_modules/rendr/server/router.js:87:11
   at Object.module.exports.create (/home/longjeongs/thinksquareio.github.io/app/controllers/users_controller.js:5:5)

我在任何地方都找不到任何编译rendr-handlebarshandlebarsgulp 的示例,我想我会尝试在这里获得一些帮助。

我在其他地方读到这是由不同的编译器把手和客户端把手版本引起的,但我相信我安装了正确的。我安装了这些依赖项

│ ├─┬ handlebars@2.0.0
├─┬ gulp-handlebars@3.0.1
├─┬ handlebars@2.0.0
├── rendr-handlebars@2.0.1

我的compiledTempaltes.js文件显示"compiler":[6,">= 2.0.0-beta.1"]. 我对车把的 gulp 任务执行以下操作;

gulp.task('handlebars:compile', function () {

    return gulp.src('./app/templates/**/[!__]*.hbs')
        .pipe(plumber())
        .pipe(handlebars({ wrapped : true, handlebars: require('handlebars') }))
        .pipe(wrap('templates["<%= file.relative.replace(/\\\\/g, "/").replace(/.js$/, "") %>"] = <%= file.contents %>;\n'))
        .pipe(concat('compiledTemplates.js'))
        .pipe(wrap('module.exports = function(Handlebars){\ntemplates = {};\n<%= contents %>\nreturn templates \n};'))
        .pipe(gulp.dest('app/templates/'));
});

我试过安装不同版本的把手、rendr-handlebars 和 gulp-handlebars,但运气不佳,我们将不胜感激。

4

1 回答 1

0

我在我的rendr项目中使用gulp...我制作了一个示例应用程序,您可以查看... https://github.com/jaredrada/rendrjs-demo

浏览器同步存在一些问题,我已在本地修复 - 因此,如果您复制整个 gulp 设置,该部分将无法正常工作。我会将我的编辑推送到 github 存储库。

于 2015-11-11T23:44:20.160 回答