I'm currently preparing an evaluation JavaScript modularization approaches for my corp. We are in process of defining "JavaScript Best Practices" for our projects, modularization is one of the central questions.
From my research so far revealed two leading approaches:
With a huge number of loaders, plugins, libraries etc. around them.
Apart from that there's also goog.provide
/goog.require
from the Google Closure Library.
Are there further approaches to consider? Any important/relevant specs I missed?
Our requirements, briefly:
- Structure JavaScript code in separate files.
- Load relevant modules in the runtime.
- ...without having to include every single file as script tag.
- Must not be necessary to maintain an index of JavaScript files.
- Support aggregation and minification - ability to build and use a single minified/optimized JavaScript file.
- Be able to use modules in different combinations - there are often different web pages/clients which need different subsets of modules.
- Supporting documentation (with JSDoc?).
- Suitable for testing.
- Suitable for web, cross-browser.
- Reasonable IDE support.
Potentially:
- Aligned with ES6 modules.
- Suitable for Node.js and mobile platforms (like PhoneGap/Cordova).
New suggestions from answers:
- ecmascript-harmony plus extra compiler.
- angularjs (see the note below).
- extjs (see the note below).
Side notes:
- The question is not about which approach is better.
- I am not asking for specific libraries and tools, but rather for approaches and specifications.
- I am not specifically asking for an off-site resource. (If there's no SO tag for this, it's probably not reasonable for us to consider it.)
- A note on frameworks like angualjs or extjs. This is not really suitable in the frame of this quesion. If the project needs a framework (be it AngularJS or ExtJS) then there's mostly no modularization question as the framework must deliver modularization OOTB. If the project does not need a framework, it is an overkill to bring a framework because of the modularization. This is one of the reasons I am specifically not asking about libraries/tools.
How about ES Harmony?
quote from here: http://addyosmani.com/writing-modular-js/
hopeThatHelps