2016-10-31 59 views
0

我知道有一些「筆中間件」的問題,但我還是沒有弄明白又手寫中間件蒸餾水和SRC路徑..的Node.js - 在expressjs

所以我想編譯.styl文件每次運行節點app.js

var express = require('express'); 
var stylus = require('stylus'); 
var nib = require('nib'); 
var app = express(); 

app.set('view engine', 'jade'); 

app.use(express.static(__dirname + '/public')); 

app.use(stylus.middleware({ 
    src: __dirname + 'stylus', 
    dest: __dirname + 'stylesheets', 
    force: true, 
    compress: true 
})); 

我已經在公共創建靜態目錄.. 這是我的文件夾hirearchy(我刪除了node_modules一會兒讓簡單的樹)

MyApp: 
-public 
    - stylus 
    - stylesheets 
    - images 
    - javascript 
-views 
-routes 
-app.js 
-package.json 

所以用這個代碼,每次我RAN節點app.js筆中間件的Wnt編譯樣式文件中/public/stylus/style.styl並把編譯後的文件(CSS)在/public/stylesheets/style.css

三江源所有:)

回答

0
var express = require("express") 
var stylus = require("stylus") 
var path = require("path") 
// var expressStylus = require("express-stylus") 

var app = express(); 

app.use("/public", express.static(path.join(__dirname,"public"))) 

// If you are using stylus use this syntax 
// stylus doesn't take on object as parameter 
app.use(stylus.middleware(path.join(__dirname, 'public'))); 


/** 
express-stylus module can take an object as a parameter 
app.use(expressStylus.middleware({ 
    src: path.join(__dirname, "public", "stylus"), 
    dest: path.join(__dirname, "public", "styleSheets"), 
    force: true, 
    compress: true 
})) 
*/ 

app.get("", function(request, response) { 
    response.render("index") 
}) 


app.listen(app.get("port"), function() { 
    console.log("The server is running on http://localhost:%s", app.get("port")) 
}) 

,我用這個目錄結構 - 公共 - style.styl - 觀點 - 航線 - app.js - 的package.json