これは、私がアプリケーションに使用する優れた技術スタックです。
サーバ側:
- Express.js
- ハンドルバー
- Passport.js
- マングース
- モンゴDB
- Caolanフォーム(ただし、現在、独自のフォームハンドラーを実装中です)
- コーヒースクリプト
クライアント側:
- ハンドルバー
- Jクエリ
- Require.js
- Backbone.js
- text.js (require.js のプラグイン)
- Coffeescript (require.js のプラグイン。私の .coffee は、r.js を使用して、dev ではクライアント側でコンパイルされ、prod ではサーバー側でコンパイルされます)
必要に応じて、後で小さなサンプル アプリを作成するかもしれません。
[編集]
これがサンプルアプリです。
プロジェクトの構造:
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');
アプリケーション.コーヒー
... standard express.js initialization
require("./routes")(app)
... start server
インデックスコーヒー
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);
})
サンプルビュー.コーヒー
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 ミドルウェアを使用して、style.less をコンパイルできます。
すべてのクライアント アプリケーションをr.jsでプリコンパイルできることを忘れないでください。
このページが忘れられず、将来このページに出くわした人の助けになることを願っています。