Compile CoffeeScript files on Node.js start with connect-assets

If I have != js('engagement') in my .jade file, and that CoffeeScript file will compile into a .js file on page load and I can then access to the .js file directly.

But I cannot start my Node.js server and go directly to the .js file with /js/engagement.js in the url.

Is there some simple code that I suppose to put in my app.js to get the package "connect-assets" working different for compiling this?

I call this specific problem "priming"; you want to use these files without referencing them in any views. It's especially problematic with architectures involving requireJS on the front end.

I've created a module called connect-assets-jsprimer that will prime all your coffeescript files on app startup so that they are available. In essence, it just calls the connect-assets js("") function on all the files in you assets/js folder (recursively).

Install with:

npm install connect-assets-jsprimer

Usage (in your server.js or whatever)

var assets = require('connect-assets');
var jsPrimer = require('connect-assets-jsprimer');

// Snip ...

app.use(assets());
jsPrimer(assets);

// Optionally, you can pass in a log function to see progress
// jsPrimer(assets, console.log);

After this, you should be able to request your javascript files straight away without rendering any views.

Source is up on github at connect-assets-jsprimer