0

im using stylus to my nodejs application (not express, just plain node). Im also using nodemon to monitor changes and apply them without restarting my app. I have a little sh script that runs my app:

#!/bin/sh

if [ -f style/*styl ]; then
  echo "Building *styl..."
  node_modules/stylus/bin/stylus -c style/*styl
fi
echo "Running src/app/index.js..."
nodemon src/index.js

As you can see, the scripts compiles the stylus into css if found before running the application. Is this the correct way of compiling stylus styles? Or should I use the js library within my code?

Also, as It gets compiled before running the application, changing the *styl won't get reflected without restarting the application, obviously.

Any way to achieve this? To set stylus to compile when the file is changed without restarting app?

jviotti
  • 17,881
  • 26
  • 89
  • 148

1 Answers1

3

When you run the express binary it bootstraps a Node.js / Express application for you. In its app.js Stylus gets referenced and activated as a middleware.

The way Stylus is configured in this scenario causes .styl files to automatically (!) recompile to .css files once they are changed.

So no need to manually do anything.

PS: Stylus and Express - stylesheets are not re-compiled when modified may be of interest to you.

Community
  • 1
  • 1
Golo Roden
  • 140,679
  • 96
  • 298
  • 425
  • but as I said above, im not using express... what would be the right way with plain node? – jviotti Sep 24 '12 at 04:48
  • You do not need to run Express to make use of this. Simply run the express binary, and look how Stylus is embedded then, copy that, and use it without Express ;-) – Golo Roden Sep 24 '12 at 05:16
  • So do you use Connect? If not, then it's my fault - since you need something where you can embed the Stylus middleware into. So - do you? – Golo Roden Sep 24 '12 at 05:18
  • Not using connect, though reading about it seems like it worth it – jviotti Sep 24 '12 at 19:13