0
votes

i know there are some 'Stylus Middleware' question but still i haven't figure it out yet..

so I'd like to compile .styl file every i run node 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 already create the static directory in public.. And this is my folder hirearchy (i deleted the node_modules for a while to get simple tree)

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

So with this code, everytime i ran node app.js stylus middleware wnt compile the style file in /public/stylus/style.styl and place the compiled file(css) in /public/stylesheets/style.css

Thankyou all :)

1

1 Answers

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

and I use this directory structure - public - style.styl - views - routes - app.js - package.json