Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preparing client side Coffeescript: compiling, uglifying gzipping

On server side I am using Connect and Socket.IO. I want to serve my client side code (also CofeeScript) to be compiled (to JavaScript), uglyfied and gzipped. I looked for Conenct middleware to do this to me and found uglify-js-middleware and gzippo.

However I am not sure what's a good way to have it converted to JavaScript first (is there no API or something?) and whether I should use temporary directories for every step so I can use the src and dest options of uglify-js-middleware and gzippo or whether there is a better way to pipe it through all these things.

It's okay when this simply gets done when starting my application and so I don't care about checks or anything. I could probably use Cake somehow, but I don't really want to add an extra script for this and it would be cool if I could just pipe it so I don't have the need for temporary directories.

Is there maybe some kind of Middleware that does all of this? I really don't think I am the first one who wants to do this.

Oh and maybe the CofeeScript from a client side directory could be combined into one file, but I guess that's not really a problem.

like image 581
knex Avatar asked Sep 08 '11 16:09

knex


2 Answers

Ah, if only someone had written a Connect middleware modeled on the Rails 3.1 asset pipeline... oh wait! I recently did: http://github.com/TrevorBurnham/connect-assets

It's pretty early-stage, but it does exactly what you want: compiles CoffeeScript files to JavaScript, concatenates and minifies them in production mode, and doesn't create new files (so no extra git diffs). Try it out and let me know what you think.

like image 139
Trevor Burnham Avatar answered Nov 09 '22 18:11

Trevor Burnham


check out the compiler middleware: http://senchalabs.github.com/connect/middleware-compiler.html. It does exactly what you want.

app.use express.compiler
    src: "#{__dirname}/public/scripts"
    enable: ['coffee-script']
like image 33
Ricardo Tomasi Avatar answered Nov 09 '22 18:11

Ricardo Tomasi