Node.js - expressjs中的Stylus Middleware dest和src路径

时间:2016-10-31 10:02:03

标签: css node.js express middleware stylus

我知道有一些'Stylus Middleware'问题,但我仍然没有想出来......

所以我想每运行节点app.js

编译.styl文件
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

所以使用这段代码,每次我运行节点app.js手写笔中间件wnt编译/public/stylus/style.styl中的样式文件,并将编译后的文件(css)放在/public/stylesheets/style.css中

谢谢你们所有人:)

1 个答案:

答案 0 :(得分: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