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阅读原文】。感谢您的支持!

您可能感兴趣的

Heroku: Node, Express, PostgreSQL Setup Step 1: Install Heroku Install the heroku cli with homebrew $ brew ins...
教你用 Web Speech API 和 Node.js 来创建一个简单的 AI 聊天机器人... 简评:使用语音命令在今天变得非常普遍,许多手机用户使用像 Siri 和 Cortana 这样的语音助手,我们的卧室也被亚马逊的 Echo 和 Goog...
Nodejs 之 exports, require, module, __filename, __d... Nodejs代码中常见的引入模块函数“require”。其实很少人了解为什么能使用“require”,以及Nodejs基本的运行机制。 是否还记得“argu...
Announcing the general availability of Azure Appli... At Microsoft, we are committed to enabling great experiences for developers bui...
list partitions in nodejs I would like to get the list of partitions in windows, using nodejs. fs.readdir ...