UMD-Inspired JS Module Boilerplate
This is the module format you don't know you need until you need it. Write your module once and have it work in a CJS/NodeJs, AMD, YUI (v3+), or Browser Global environment.
Best Used When...
- You are migrating from namespaced (err, globals) code to either AMD or CJS modules or both.
- You can't yet factor out browser globals but also need to test your code via NodeJS (e.g. Mocha).
Benefits & Trade-offs
- A single module format allowing you to target AMD, CJS/NodeJS, and legacy browser globals like
- Allows multiple dependencies to be defined.
- Run unit tests via CLI/NodeJS runner (e.g. Mocha).
- Less pain while incrementally migrating to CJS/NodeJS or AMD modules.
- You give up the Java-like namespaces (e.g. com.company.package.module) -- meh, they are a mess anyway.
- This (UMD) isn't a standard; to be fair, neither is AMD (it's a convention with a well-defined spec).
- Non-trivial amount of boilerplate (and Ugly).
- http://www.youtube.com/watch?v=TqX-CqYYwEc (skip to 17:00)
Further Reading for your edification
- RequireJs Exported Value
- AMD is Not the Answer (anti-amd)
- Building The Next SoundCloud (cjs+amd)