NodeJS Express app generation with CoffeeScript and HAML

ε祈祈猫儿з 提交于 2019-12-25 02:26:45

问题


I just started looking into NodeJS and Express and found out about the possibility to generate a new app that uses hogan right from the start:

express <appname> -c [stylus, less] --hogan --ejs

Is there a way to generate a new app that uses CoffeeScript, HAML instead of Jade and Less/SCSS ?


回答1:


I don't think there is a generator, but you can easily make an express app using HAML and coffeescript.

package.json:

{
  "name": "haml-coffee-express",
  "dependencies": {
    "express": "",
    "express-partials": "",
    "haml-coffee": "",
    "coffee-script": ""
  }
}

server.coffee:

express = require("express")
partials = require("express-partials")
app = express()
app.engine "hamlc", require("haml-coffee").__express 
app.use partials()

app.set "view engine", "hamlc"

app.get "/", (req, res) ->
  res.render "index",
  name: "User"

app.listen 3000
console.log "App started on port 3000"

views/layout.hamlc:

!!!
%head
  %title Express App
%body
  != @body

views/index.hamlc:

%h1= "Welcome #{ @name }"
%p You've rendered your first Haml Coffee view.


Afterwards, just run this command and you are good to go.

npm install && node_modules/coffee-script/bin/coffee server.coffee



来源:https://stackoverflow.com/questions/22116481/nodejs-express-app-generation-with-coffeescript-and-haml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!