2016-10-31 4 views
0

ich weiß, gibt es einige ‚Stylus Middleware‘ Frage, aber noch habe ich es nicht herausgefunden noch ..Node.js - Stylus Middleware dest und src Pfad in Express.js

so würde Ich mag .styl kompilieren Datei jedes i laufen Knoten 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 
})); 

i erstellen bereits die statische Verzeichnis in der Öffentlichkeit .. Und das ist mein Ordner hirearchy (i löschte die node_modules für eine Weile einfachen Baum zu erhalten)

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

Also mit diesem Code jedes Mal lief i Knoten app.js Stift Middleware Wnt die Stildatei in /public/stylus/style.styl kompilieren und legen Sie die kompilierte Datei (CSS) in /public/stylesheets/style.css

Vielen Dank all :)

Antwort

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")) 
}) 

und ich verwende diese Verzeichnisstruktur - public - style.styl - Ansichten - Routen - app.js - package.json

Verwandte Themen