loader-resolve.mustache revision 62898daffb90e74ea7a9000bf3e0fdc9e570b7a2
d6fa26d0adaec6c910115be34fe7a5a5f402c14fMark Andrews<div class="intro">
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt<p>Loader can be used programatically as an offline dependency calculator.</p>
5347c0fcb04eaea19d9f39795646239f487c6207Tinderbox User<h2>Instantiating Loader</h2>
5347c0fcb04eaea19d9f39795646239f487c6207Tinderbox User<p>Loader comes with the `YUI` seed file by default, so it's ready to be used immediately, so there is
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Huntno need to load any additional files.</p>
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Huntvar Y = YUI();
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Huntvar loader = new Y.Loader();
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt<h2>Resolving dependencies</h2>
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt<p>`Loader` comes with a `resolve` method that it uses internally to calculate dependencies and
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Huntbuild URL's for injecting scripts into the page.</p>
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Huntvar Y = YUI();
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Huntvar loader = new Y.Loader({
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt require: [ 'node' ]
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt//Tell loader to calculate dependencies
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt<p>In the above code, `out` will be an Object containing the keys, `js` and `css` that will contain
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox Useran array of URL's to load the modules needed to resolve `node`.</p>
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User<h2>Advanced Usage</h2>
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User{{>loader-resolve}}
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User<p>The above code will generate this URL for you:</p>
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User<div class="example code" id="resolve1">
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt{{>loader-resolve}}
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox Userdocument.getElementById('resolve1').innerHTML = out.js[0];
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt<p>You can use any `Loader` configuration option here as well: `modules`, `groups`, `patterns`, etc.</p>
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User<h2>CLI use within Node.js</h2>
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User<p>Here we use Loader to calculate dependencies from the command line and generate a combined
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox Userfile. This could be used in a build system to auto-generate a custom seed file with modules
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox Userneeded for immediate access.</p>
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User{{>loader-resolve-node}}