Nathan Wall
Nathan Wall

Reputation: 10704

Are there tools for compiling CommonJS modules into a single .js file?

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?

Upvotes: 6

Views: 1933

Answers (3)

Dmitry Sheiko
Dmitry Sheiko

Reputation: 2192

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.

Upvotes: 1

Matthew
Matthew

Reputation: 15992

If you want something you can use directly from PHP, try cjsDelivery.

Upvotes: 0

jAndy
jAndy

Reputation: 236122

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!"

Upvotes: 4

Related Questions