grunt-commonjs-compiler
Grunt task for compiling client-side CommonJS modules into one file.
It takes only required files, not everything.
Installing
npm install grunt-commonjs-compiler
Also you can add --save or --save-dev to save this dependency in package.json:
npm install grunt-commonjs-compiler --save-dev
Adding Grunt task
Modify Gruntfile.js:
module { grunt; grunt; };
compiler.jar
grunt-commonjs-compiler uses Closure Compiler to compile and optimize CommonJS modules.
You can obtain it here
Quick example
To see it in action without smoking too much of documentation:
Download stuff
git clone https://github.com/Indamix/grunt-commonjs-compiler.git .npm installcurl http://dl.google.com/closure-compiler/compiler-20131014.tar.gz | tar zx
Compile example project
grunt test
grunt-commonjs-compiler will build a CommonJS module tree starting from test/client/main.js and write the compiled code to test/build.js
Notice that the compiled build doesn't include test/client/unused.js as no module requires it.