2

I'm totally new to all the node shenanigans and don't quite know the best solution for the issue I have, maybe someone can point me towards the best solution towards it.

I have a setup with the framework Buddy to compile coffeescript into JS, all runs smoothly. What I need now is some tool to merge and preferably uglify and mangle the scripts together into one script.

Buddy has a nice setup where it auto-compiles the scripts upon save, is there such a tool that also watches and does said operations after Buddy has done its thing?

1
  • I'm not familiar with Buddy, but coffeescript supports concatenating the source files with coffee --join. Then you would just have to pipe it through uglify, npm install uglify-js. Commented Aug 26, 2012 at 16:22

2 Answers 2

4

There is a module for node js called uglify-js which handles minification

To install it run:

npm install -g uglifyjs

It will install a command line utility, which accepts files from standard input and outputs to standard output the minified result.

To concatenate you can simply use cat command line utility.

You can concatenate all the CoffeeScript files before the minimization or after.

Both have tradeoffs.

By concatenating before, you will avoid dublication of some supporting code that coffeescript generates, but will loose the wrapping to (function(){ /* your generated code here*/ })() that CoffeeScript generates to avoid poluting the global scope.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer, this is what I ended up doing. Made an apple script for this that I run after I have compiled the coffeescript. Any ideas of solutions to make it run when a file in a directory has changed?
The fs module in node.js itself, which allows you to watch a directory for file changes in it (actually thats what coffee -w does). nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener It works nicely on linux but not so well on Mac. Pooling for changes is another option, like recompile everything every 0.5 seconds. You can also use github.com/mynyml/watchr which allows to run a command whenever a file changes in a directory
0

See brunch. It include builder, linter, concatenator, minifier, source watcher and another useful tools.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.