Preparing client side Coffeescript: compiling, uglifying gzipping
Asked Answered
N

4

5

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.

Nambypamby answered 8/9, 2011 at 16:0 Comment(0)
H
7

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.

Honniball answered 9/9, 2011 at 19:13 Comment(2)
It looks great, but it'd be really cool to have an option so all *.coffee files get merged into one JS file (which is nice, if you split a lot of classes into many files and don't want to include them). Also, couldn't they be gzipped afterwords? Oh and you could do stuff like removing unnecessary whitespaces in files.Nambypamby
@Nambypamby Concatenation and minification is already supported; by default, it's enabled only when NODE_ENV is set to production. Gzipping is an open issue, soon to be resolved.Honniball
O
1

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']
Osher answered 10/9, 2011 at 5:18 Comment(0)
I
0

http://docpad.org can compile it on the server-side very intuitively

Impostume answered 10/9, 2011 at 5:54 Comment(0)
T
0

Has anyone seen Mincer? https://github.com/nodeca/mincer

I'm choosing a solution now, so I haven't vetted it yet, but looks like it's strongly based on Sprockets, like connect-assets.

Twelfth answered 21/5, 2014 at 20:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.