这里是我用我的应用良好的技术堆栈:
服务器端:
- Express.js
- 把手
- Passport.js
- 猫鼬
- MongoDB
- Caolan表格(但我现在是我ñ实现我自己的表单处理程序)
- CoffeeScript的
客户端的过程:
- 把手
- jQuery的
- Require.js
- Backbone.js的
- 文本.js(用于require.js的插件)
- Coffeescript(require.js的插件。我的.coffee是使用r.js在开发版和服务器端编译的客户端)
如果需要,我可能会稍后再创建一个示例应用程序。
[编辑]
确定这里是一个示例应用程序。
项目结构:
forms
|___ sampleForm.coffee
models
|___ sampleModel.coffee
public
|___ images
|___ stylesheets
| |___ style.less
|___ sampleapp
|___ main.js
|___ cs.js
|___ text.js
|___ require.js
|___ collections
| |___ sampleCollection.coffee
|___ models
| |___ sampleModel.coffee
|___ templates
| |___ sampleTemplate.hbs
|___ lib
| |___ handlesbars.js
| |___ backbone.js
|
| |___ ...
|___ views
|___ sampleView.coffee
routes
|___ index.coffee
views
|___ index.hbs
app.js
application.coffee
package.json
服务器端:
app.js
require('coffee-script');
module.exports = require('./application.coffee');
application.coffee
... standard express.js initialization
require("./routes")(app)
... start server
index.coffee
SampleModel = require "../models/sampleModel"
module.exports = (app) =>
app.get "/index", (req,res) =>
return res.render "index"
app.get "/samplemodels", (req,res) =>
SampleModel.find {}, (err, models) =>
return res.send 404 if err or !models
return res.send models
return
index.hbs
<!DOCTYPE HTML>
<html>
<head>
<title>Sample app</title>
<link type="text/css" href="/stylesheets/style.css" rel="stylesheet" >
<script src="/mainapp/require.js" data-main="/mainapp/main"></script>
</head>
<body>
<div id="main-content"></div>
</body>
</html>
main.js
require.config({...}) // Configure requires.js...
require(["jquery", "cs!models/samplemodel", "cs!views/sampleview","cs!collections/samplecollection"], function ($, Model, View, Collection) {
var collection = new Collection();
collection.fetch();
var view = new View({collection: collection});
$("body").html(view.render().$el);
})
个
sampleview.coffee
define ["backbone", "jquery", "handlebars","text!templates/sampleTemplate.hbs"], (Backbone, $, Hbs, template) =>
class MainView extends Backbone.View
initialize: =>
@collection.on "change", @render
@template = Hbs.compile template
render: =>
html = @template {models: @collection.models}
@$el.html(html)
return @
sampleTemplate.hbs
{{#models}}
<p>{{name}}</p>
{{/models}}
好了,所以这是必要的。现在您将不得不学习如何使用Backbone.Collection,Backbone.Model,如何配置Require.js,如何配置Passport.js以及如何制作Mongoose model。你可以使用Less middleware来编译你的style.less
不要忘了你可以使用r.js预编译所有的客户端应用程序。
现在我希望这个网页不会被遗忘,并且它会帮助任何未来遇到它的人。
没有MVC框架的一百年,3/4服务器端最好和相同数量的客户端。 – mpm 2013-02-19 13:21:48
@mpm:我认为你低估了。 [TodoMVC](http://todomvc.com/)列出了超过25个客户端框架,并且多于编译到客户端JS以及其他一些类别。 – 2013-02-19 13:59:02
@Scott Sauyet这些框架中有多少可以通过互联网扩展文档,博客文章,支持和教程?这就是你如何告诉框架值得使用还是不适用。从采用的角度来看,这些框架中的80%是微不足道的。 – mpm 2013-02-19 14:13:21