如何使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文件。     

解决方法

        找到答案,并添加:
compile = (str,path,fn) ->
  stylus(str).set(\'filename\',path).set(\'compress\',true)
    ,        您当然可以提供自己的编译功能,但是它会不必要地覆盖默认功能。而是在您的中间件调用中添加调试选项,并检查出问题的地方:
  app.use stylus.middleware
    debug: true
    force: true
    src: \"#{__dirname}/../public\"
    dest: \"#{__dirname}/../public\"
对我来说,问题在于设置了错误的src / dest路径。您确定您的.styl文件确实位于您的views文件夹中吗?     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...