我是Node和javascript后端框架的新手,所以请容忍我:
我一直在寻找前端和后端(MVC)框架的一个很好的组合来使用Node,我现在决定使用SailsJS/EmberJS来制作一个样板,我可以尝试一下,也许可以在未来的项目中使用。
SailsJs (开箱即用生成的应用程序)使用EJS来编译后端视图。EmberJs (默认情况下,初学者工具包)使用handlebars来编译前端视图。
我希望保持模板语言(EJS)的原样,只有一个例外是关于SailsJS的链接器。它目前将公共模板编译为“jst.js”,这与handlebars不兼容。我想改变这一点,以便'jst.js‘将包含车把编译的模板,因此它们被提供给前端(ember应用程序),所有准备好使用。
我假设这需要一个额外的节点库。为了让链接器将handlebars编译后的模板输出到公共目录,我应该如何配置Gruntfile.js以使用该库?
发布于 2014-03-10 18:29:34
Sails中的EJS模板与Ember的模板关系不大。Ember和其他客户端应用程序框架的一个关键方面是渲染是如何在客户端完成的,而不再是在服务器上。与使用Sails EJS模板向用户提供初始有效负载不同,Sails将作为REST API与Ember一起工作得最好。至于如何处理预编译handlebar模板以优化初始有效负载,您可以看看Ember App Kit是如何实现的。事实上,EAK是一个很好的起点,原因有很多。
发布于 2014-09-23 23:47:30
在当前版本的grunt-ember-templates中,不知何故,dev:部分无法工作。一旦我把它去掉,它马上就能工作了:
var pipeline = require('../pipeline');
module.exports = function(grunt) {
grunt.config.set('emberTemplates', {
compile: {
options: {
amd: true,
templateBasePath: pipeline.templateBasePath
},
files: {
'.tmp/public/jst.js': pipeline.templateFilesToInject
}
}
});
grunt.loadNpmTasks('grunt-ember-templates');
};发布于 2014-09-14 04:27:32
你现在可能已经弄明白了,但我要说的是...
查看https://github.com/dgeb/grunt-ember-templates中的“附加节点库”
有关如何配置任务的信息,请参阅http://sailsjs.org/#/documentation/concepts/Assets/TaskAutomation.html?q=task-configuration。
我让它工作的方法是在tasks\config\emberTemplates中创建以下文件
var pipeline = require('../pipeline');
module.exports = function(grunt) {
grunt.config.set('emberTemplates', {
dev: {
compile: {
options: {
amd: true,
templateBasePath: pipeline.templateBasePath
},
files: {
'.tmp/public/jst.js': pipeline.templateFilesToInject
}
}
}
});
grunt.loadNpmTasks('grunt-ember-templates');
};并使用以下代码行修改tasks\pipeline.js
var templateBasePath = 'assets/templates/';
var templateFilesToInject = [
templateBasePath + '**/*.hbs' //Note that whatever is replaced by '**/' will be included in the template name (necessary for defining components see http://emberjs.com/guides/components/defining-a-component/).
];
module.exports.templateFilesToInject = templateFilesToInject;
module.exports.templateBasePath = templateBasePath;当然,还可以将模板放在带有.hbs扩展名的assets/templates中。
https://stackoverflow.com/questions/21951961
复制相似问题