In development, recompiling .css every time .styl changes is highly convenient. But on production, we don't want to spend resources compiling on every request; we'd like to compile once, on app start.
Can Stylus be configured this way?
SocketStream has an asset packer than pre-compiles the css, js and template files in production mode. Perhaps use that pattern of checking for an environment variable (development or production) and then serving either an on-the-fly compiled set of files, or a pre-packed set of assets that are done when node starts for the first time (i.e. compile your css and then use the fs module to write them to disk).
The following is taken from the stylus module of socketstream:
stylus(input, {filename: path, paths: [dir.join('/')]})
.render(function(err, css) {
if (err) {
console.log(err);
}
cb(css);
});
The cb method is the callback that is used to feed a fs.writeFileSync call that takes in the compiled file. So, in the end you have 4 parts: