這裏是我用我的應用良好的技術堆棧:
服務器端:
- 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