这是我用于应用程序的良好技术堆栈:
服务器端:
- Express.js
- Handlebar
- Passport.js
- Mongoose
- MongoDB
- Caolan表单(但是我目前正在实现自己的表单处理程序)
- Coffee script
客户端:
- Handlebar
- jQuery
- Require.js
- Backbone.js
- text.js(require.js的插件)
- Coffeescript(require.js的插件。我的.coffee是使用r.js在dev的客户端编译和在prod的服务器端编译)
如果需要的话,我可能会在以后制作一些示例应用程序。
[编辑]
好的,这是一个示例应用程序。
项目结构:
forms |___ sampleForm.coffeemodels |___ sampleModel.coffeepublic |___ 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.coffeeroutes |___ index.coffeeviews |___ index.hbsapp.jsapplication.coffeepackage.json
服务器端:
app.js
require('coffee-script');module.exports = require('./application.coffee');
应用coffee
... standard express.js initializationrequire("./routes")(app)... start server
索引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模型。您可以使用Less中间件来编译样式。
不要忘记,您可以使用r.js预编译所有客户端应用程序。
现在,我希望不要忘记此页面,希望对以后遇到的任何人有所帮助。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)