create.mustache revision 4d9eb2dc9f09844d55fcd5d9aa361af3d4d9e464
98N/A<p>In this example we will show you our recommended approach to creating your own `YUI` modules.</p>
911N/A<p>A `YUI` module can be described as <em>"any code that can be separated to run on it's own"</em>.
98N/A<p>`YUI` gives you a few options on how to tell it about your modules. The simpliest way is to include your modules
98N/A<p>If all of your modules are wrapped in a valid `YUI.add` call, `YUI` will know about them just
98N/Abecause they are on the page. The calls to `YUI.add` tell the `YUI` seed all that it needs to know
98N/A<script src="/path/to/yui-min.js"></script>
98N/A<script src="/path/to/my/module1.js"></script>
98N/A<script src="/path/to/my/module2.js"></script>
98N/A<script src="/path/to/my/module3.js"></script>
98N/A<p>The local use case may not be good for you if you have several modules that you would like `YUI` to know about.
911N/AIn this case, you would want to tell `YUI` about your modules so that it can fetch them when they are required.</p>
911N/A<p>To do this, you need to use one of the <a href="index.html#config">various ways to configure</a> `YUI` and
705N/A<p>In this example, we will use the `YUI.GlobalConfig` to tell all `YUI` instances about our modules (Note: this must come <em>after</em> the YUI seed file in the page's source):</p>
493N/A module1: '/path/to/my/module1.js',
98N/A module2: '/path/to/my/module2.js',
fullpath: '/path/to/my/module3.js',
<p>The advantage of this approach is that we now have all of our modules information in one simple location
<p>In larger projects, you may need to structure your modules in a common way if you have multiple developers working
on the code. In this case, you can follow `YUI`'s model on this and structure your code to get the most use
<p>Now that your files are structed in a parsable manner, `Loader` can handle them without much of a configuration.</p>
<p>By default, when `Loader` is attempting to fetch a static module, it will create a url using a few config options:
<p>There are several combo handlers for different languages, so we won't discuss them here. Basically
a combo handler is an entry point on your server that accepts a query string of a list of files. The
server then combines all those files and returns the output. This allows you to ask for multiple files
<p>`YUI` has always had this support built in for it's core files, but you can have this with your modules too.
Configuring `YUI` to use a custom combo handler is extremely easy, let's modify the above example to use a
<p>When `Loader` is attempting to fetch a set of combined modules, it will create a url using these config options:
<comboBase><root><modulename>/<modulename>(-<filter>).js<comboSep><root><modulename>/<modulename>(-<filter>).js
<p>Now you have a flexible, scalable and dynamic module loading system that will let you build large scale
at our `Ant` based build system tool called <a href="https://github.com/yui/builder/">builder</a>.</p>
<p>`YUI` uses <em>aliases</em> under the hood as module "shortcuts", for example, when you `use` "node"
`Loader` doesn't fetch a `node.js` file, it actually fetches several files under the hood that make up the "node"
YUI.GlobalConfig = {
<p>This will create an alias called `all` for the modules: `'module1', 'module2', 'module3'`. You can then