in a node.js environment, instead of stylus generating the .css each time, would like to write the .css file to a directory to be served by nginx.
seems that versioning part of name, eg, client-<unixTime>.css, then nginx will be happy and page caching will work correctly.
are there any existent tools available for helping with this?
did not realize that
styluswas also an executable that can be run one-time or as a demon. in either case will convert the.stylfiles to.css, putting them in the directory of your choice.in
node.js, to get the executablefor me, using
stylusthis way is much preferred because of the way inflexibility of thestylus middleware. rather than address that, using executable. this also keeps the development and productionnodeserver more closely aligned, but does not solve the versioning issue.here is my function that compiles one file (synchronous):
var stylus = require('stylus'), nib = require('nib'); // compile stylus exports.css = function( fn, out ) { var buf = fs.readFileSync( fn, 'utf8' ); var oldCode = ( fs.existsSync( out ) ) ? fs.readFileSync( out, 'utf8' ) : 'none'; stylus( buf ) .set( 'filename', fn ) .use( nib() ) .render( function(err,newCode) { if( err ) throw( 'stylus err: '+err ); if( oldCode != newCode ) { console.log( 'stylus: creating '+out ); fs.writeFileSync( out, newCode, 'utf8' ); } }); };(after compiling I gzip using non-current
gzfiles usingcompress-buffer(sync)