AMD allows defining dependencies in a resource which is loaded by a module basing on a loader plugin.
Loader plugins can load resources thanks to the AMD loading mechanism and benefit from the same performances and parallel loading.
There are some useful loader plugins:
Using configuration in GateIn for AMD loader plugin target resource is straightforward. For example, you
want to build some HTML by JavaScript, the
text.js
AMD loader plugin can address this issue. The plugin will load the template (plugin's resource) and pass it
into your module definition callback as a parameter.
Declare
text
as a GateIn module which is written as a native module depends on a predefined module of RequireJS module.
Thanks to the native support mechanism, this configuration works
transparently without modifying the third party library.
<module>
<name>text</name>
<script>
<path>/requirejs/js/plugins/text.js</path>
</script>
<depends>
<!-- here module means RequireJS itself -->
<module>module</module>
</depends>
</module>
Define your
foo
module that needs the
text
plugin to load the template via the
resource
XML tag:
<module>
<name>foo</name>
...
<depends>
<module>text</module>
<as>myTemplate</as>
<resource>/path/to/template.tmpl</resource>
</depends>
</module>
Load the template of the
foo
module by the
text
plugin:
(function(myTemplate) { //parse the 'myTemplate' then append to DOM })(myTemplate);