如何让 Stylus 在 CoffeeScript 中与 Express 和 Connect 配合使用
我的 app.coffee 看起来像这样:
connect = require 'connect'
express = require 'express'
jade = require 'jade'
stylus = require 'stylus'
app = express.createServer()
# CONFIGURATION
app.configure(() ->
app.set 'view engine', 'jade'
app.set 'views', "#{__dirname}/views"
app.use connect.bodyParser()
app.use connect.static(__dirname + '/public')
app.use express.cookieParser()
app.use express.session({secret : "shhhhhhhhhhhhhh!"})
app.use express.logger()
app.use express.methodOverride()
app.use app.router
app.use stylus.middleware({
force: true
src: "#{__dirname}/views"
dest: "#{__dirname}/public/css"
compress: true
})
)
# ROUTES
app.get '/', (req, res) ->
res.render 'index',
locals:
title: 'Title'
# SERVER
app.listen(1234)
console.log "Express server listening on port #{app.address().port}"
更新: 我根本无法用它来编写 CSS 文件。
My app.coffee looks like this:
connect = require 'connect'
express = require 'express'
jade = require 'jade'
stylus = require 'stylus'
app = express.createServer()
# CONFIGURATION
app.configure(() ->
app.set 'view engine', 'jade'
app.set 'views', "#{__dirname}/views"
app.use connect.bodyParser()
app.use connect.static(__dirname + '/public')
app.use express.cookieParser()
app.use express.session({secret : "shhhhhhhhhhhhhh!"})
app.use express.logger()
app.use express.methodOverride()
app.use app.router
app.use stylus.middleware({
force: true
src: "#{__dirname}/views"
dest: "#{__dirname}/public/css"
compress: true
})
)
# ROUTES
app.get '/', (req, res) ->
res.render 'index',
locals:
title: 'Title'
# SERVER
app.listen(1234)
console.log "Express server listening on port #{app.address().port}"
Update: I don't get it to write the CSS-files at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
找到答案,补充:
Found the answer, added:
您当然可以提供自己的编译函数,但它不必要地覆盖默认函数。相反,将调试选项添加到中间件调用中并检查哪里出了问题:
对我来说,问题是设置了错误的 src/dest 路径。您确定您的 .styl 文件确实位于您的视图文件夹中吗?
You can of course provide your own compile function, but it unnecessarily overrides the default one. Instead, add debug option to your middleware call and inspect where things are going wrong:
For me, the problem was setting the wrong src/dest path. Are you sure your .styl files are indeed located in your views folder?