Note that there are some explanatory texts on larger screens.

plurals
  1. POComparison of methods to create a toolchain: JS modules / loader / build
    primarykey
    data
    text
    <p>In the process of evaluating the various approaches available to developers to use javascript modules, module loaders and build tools, i'd like some suggestions on what tools you use, and why.</p> <p>I'm currently after something that is able to:<br> -encourage modular code<br> -allow features to be added based on necessity to a given module [think mixins/inheritance]<br> -produce a BUILD that contains a development release, and at the very minimum a production release with different layers (say, i want a layer [a script] which contains my bootstrap code, module 1, 2 and 3; and then another layer which contains modules 4,5 and 6. This way I can defer loading of code based on what's actually going on in the application.)<br> -Work [when built for production] in an extremely low bandwidth scenario, with xfer speeds of 1kbps and high latency (think worst case mobile connection over GPRS to get the picture). </p> <p>I've seen the following: Using prototype inheritance, as in:</p> <pre><code>myNS.thing = function(){}; myns.thing.prototype = { something: "foo" } </code></pre> <p>Which can be built by simply taking the contents of this script, and appending it to the next one one wants to include in a production optimized package as a single script. Loaders in this case are simple script tag injections/eval's or similar, based on a known file.</p> <p>I've also seen other approaches, such as:</p> <pre><code>function(){ return function(){ something: "foo" } }(); </code></pre> <p>Building this already gets more complex because one has to manipulate the script, removing the wrapping self executing function and combining the return values into one object. I am not aware of an "easy" way to use available build tools. The loader approach works the same as above.</p> <p>Both of these approaches lack dependencies.</p> <p>Then we have AMD:</p> <pre><code>define("mymodule", ["dep1"], function(dep1){ return {something: dep1} }); </code></pre> <p>Some might be nauseated by its indenting, and its "ceremony", but still its quite effective, the google closure compiler knows about it natively, it knows about dependencies, and seems to have widespread adoption across the board. There are a bunch of module loaders available for it (https://docs.google.com/spreadsheet/ccc?key=0Aqln2akPWiMIdERkY3J2OXdOUVJDTkNSQ2ZsV3hoWVE#gid=2) and quite a few build tools as well.</p> <p>What other options do you know of, or have you seen used in production?</p> <p>As said, i'm interested in a combination of code syntax, loader tools and build tools. These three must exist and be working together properly. The rest is an academic excercise i'm not interested in.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload