Can Stylus be configured to compile .css once, instead of on .styl change?

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:

  1. Check an environment variable upon app start.
  2. If dev mode, then just serve up the files as you are doing now.
  3. If production mode, then pre-compile the css files and output them into a directory as a minified css file.
  4. Change references in your header HTML to the minified css file(s).