Stylus, NodeJS and Nodemon

综合编程 2018-07-23 阅读原文

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?

Problem courtesy of: jviotti

Solution

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.

Solution courtesy of: Golo Roden

Node.js Recipes

责编内容by:Node.js Recipes阅读原文】。感谢您的支持!

您可能感兴趣的

Why Go for Node.js Developers This article is an attempt at explaining Go as an alternative to Node.js. The following is not an attempt to convince ...
node.js: setInterval() skipping calls For an upcoming project with node.js I need to perform various housekeeping tasks at periodic times. Speci...
Node.js: Is there a synchronous version of the `ht... There is a sync-request library that is pretty easily to use. Internally it spawns a child process synchronously and...
Building a javascript app shared across node.js an... I am used to cross platform dev. On the C/C++ side it's simple, but I'm stuck with a problem when using javascript. I w...
node.js sequelize: multiple ‘where’ qu... How do i query a table with multiple conditions? Here are the examples both working: Post.findAll({ where: }).succe...