将Stylus文件输出到express3中的自定义目录

我有我的项目,并将一些代码从express2.5.7移植到express3.0.3。 我认为这几乎是一个1:1的转移,但我遇到了一个问题,无法将我的手写笔文件编译到我指定的目录中。 这是我的基本app.js设置:

/** * Module dependencies. */ var express = require('express') , routes = require('./routes') , user = require('./routes/user') , http = require('http') , path = require('path') , nib = require('nib') , bootstrap = require('bootstrap-stylus') , stylus = require('stylus'); var app = module.exports = express(); app.configure('dev', function(){ var stylusMiddleware = stylus.middleware({ src: __dirname + '/stylus/', // .styl files are located in `/stylus` dest: __dirname + '/public/css/', // .styl resources are compiled `/css/*.css` debug: true, compile: function(str, path) { // optional, but recommended console.log(path); return stylus(str) .set('filename', path) //.set('warn', true) .set('compress', true) .use(bootstrap()) } }); app.use(express.logger('dev')); app.use(stylusMiddleware); app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); app.set('view options', { pretty: true }); }); app.configure('prod', function(){ app.use(express.errorHandler()); }); app.configure(function(){ app.set('port', process.env.PORT || 3000); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.favicon()); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(app.router); app.use(express.static(path.join(__dirname, 'public'))); }); app.get('/', routes.index); app.get('/users', user.list); http.createServer(app).listen(app.get('port'), function(){ console.log("Express server listening on port " + app.get('port')); }); 

我已经testing了app.configure东西,它正在通过正确的方法(“开发”和只有一个函数的configuration)

我尝试设置自定义的srcdest ,我也做不到。 在寻找解决scheme时,我查看了手写笔的来源。 在两个单词pathes到stylcss文件应该是类似的。 如果链接到css文件在HTML中看起来像

 <link rel="stylesheet" href="css/app.css"> 

其物理path是

 public/css/app.css 

那么你的文本文件应该位于

 stylus/css/app.styl 

和Expressconfiguration应该是

 app.configure('dev', function () { ... app.use(stylus.middleware({ src: __dirname + '/stylus/', dest: __dirname + '/public/', compile: function(str, path) { ... } })); ... }); 

我在源文件中看到的

手写笔parsing所有请求,并只select那些被请求的css文件。 然后,它将css url的path名与dest选项结合起来,用path名中的stylreplacecss ,并将结果与​​你的src选项结合起来:

 // Middleware return function stylus(req, res, next){ if ('GET' != req.method && 'HEAD' != req.method) return next(); var path = url.parse(req.url).pathname; if (/\.css$/.test(path)) { var cssPath = join(dest, path) , stylusPath = join(src, path.replace('.css', '.styl')); // ... } else { next(); } }