Commits

jrburke committed 5955a87

Refs #796, make it even more explicit that shim config does not work for AMD modules

Comments (0)

Files changed (1)

 <p>Here is an example. It requires RequireJS 2.1.0+, and assumes backbone.js, underscore.js and jquery.js have been installed in the baseUrl directory. If not, then you may need to set a paths config for them:</p>
 
 <pre><code>requirejs.config({
+    //Remember: only use shim config for non-AMD scripts,
+    //scripts that do not already call define(). The shim
+    //config will not work correctly if used on AMD scripts,
+    //in particular, the exports and init config will not
+    //be triggered, and the deps config will be confusing
+    //for those cases.
     shim: {
         'backbone': {
             //These script dependencies should be loaded before loading
         'foo': {
             deps: ['bar'],
             exports: 'Foo',
-            // init will be called only for non-AMD scripts
             init: function (bar) {
                 //Using a function allows you to call noConflict for
                 //libraries that support it, and do other cleanup.
                 //function arguments. If this function returns a value,
                 //then that value is used as the module export value
                 //instead of the object found via the 'exports' string.
+                //Note: jQuery registers as an AMD module via define(),
+                //so this will not work for jQuery. See notes section
+                //below for an approach for jQuery.
                 return this.Foo.noConflict();
             }
         }
     AMD module may not be evaluated until after the shimmed code in the build
     executes, and an error will occur. The ultimate fix is to upgrade all the
     shimmed code to have optional AMD define() calls.</li>
-    <li>The init function will <strong>not</strong> be called for AMD modules. 
+    <li>The init function will <strong>not</strong> be called for AMD modules.
     For example, you cannot use a shim init function to call jQuery's noConflict.
-    See <a href="jquery.html#noconflictmap">Mapping Modules to use noConflict</a> 
+    See <a href="jquery.html#noconflictmap">Mapping Modules to use noConflict</a>
     for an alternate approach to jQuery.</li>
 </ul>