Are there any tools that can compile modules written with CommonJS/Node-like modules (require
, exports
, etc.) into a single .js file to be served to a browser?
Sounds like you're looking for Browserify:
https://github.com/substack/node-browserify
"Make node-style require() work in the browser with a server-side build step, as if by magic!"
Another quite similar utility named CommonJS Compiler and Grunt task respectively you can find at https://github.com/dsheiko/cjsc
It uses Esprima syntaxTree while parsing require() calls in the modules. It enclosures each module in a unique scope and does the caching in the very way nodejs does. It works fine with UMD (universal module definition) modules. What I like most, it adds during compiling very little of code - small require function body plus define-call wrapper per module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With