Optimize a node project to a single JS file for distribution release.
npm install node-optimizenode-optimize
=============

We all need a tool to optimize a node.js project and create a single js file from it,
Taking care of requires and leaving out node_modules.
Well I needed one too, and there wasn't one, so I build it!
Usage:
``javascript
`
var NodeOptimizer = require('node-optimize');
var optimizer = new NodeOptimizer({
ignore: [
'config/db.js',
'private/some-other-file.js',
]
});
var mergedJs = optimizer.merge('main.js'); // node-optimize will automatically resolve that path for 'main.js' using path.resolve(...)
require('fs').writeFile(require('path').resolve('main.optimized.js'), mergedJs);
options.ignore
What's in the bag
* -> Tell it which files to ignore in the process of expanding the require calls.
node_modules
* Automatically ignores core modules, or modules from .
.js
Currently handles , *.json, and directory modules (with or without package.json/main).
require
* Functionality of statements stay the same - loading on demand, loading once, and synthesizing the module global object.
include
* Handling of cyclic references same as node.js's' native implementation
* Using option to include files which are not automatically detected (because of dynamic requires using variables and other complex loading mechanisms)
require
* Loading modules which were specified using complex statement (i.e. require(moduleName + '_' + index))
require
Note: Support for of module folders (with parsing of package.json etc.) will be added in the future.
node_modules
CoffeeScript
If you need support for CoffeScript, simply use Grunt to "compile" your Coffee files, and then run the optimizer on a pure JS project.
Binary modules
There's no simple way to embed native binary modules (*.node), or modules that depend on other local raw files.
In case you have a module which is known to have binary files, you should exclude it from optimization, and put it in a known path, or on a private NPM etc.
I've tried to also support squashing for cases where one wants to eliminate the need of an npm install in a production project,
node_modules
but I have abandon those trials, as it makes no sense:
In 99% of the cases on of the modules in the tree will have binaries, and npm install/npm update` is a strength anyway as it allows for bugfixes even in a production project.