简体   繁体   中英

requirejs shim amd library dependencies

I understand how to use requirejs config to set up dependencies between non-AMD libraries like backbone and underscore. It's my understanding that shim is only for non-AMD libraries. How do I use requirejs to set up a dependency between AMD libraries? Will something like this work?

require.config( {
      paths: {
            backbone             : "lib/backbone-min",
            jquery        : "lib/jquery-1.10.1.min",
            liba : 'lib/AMD-compliant-lib-a',
            libb : 'lib/AMD-compliant-lib-b-that-depends-on-a'
      },
      shim: {
            backbone: {
                  "deps": [ "underscore", "jquery" ],
                  "exports": "Backbone"  
            }, 
            underscore: {
                "exports": '_' 
            }, 
            libb: {
                "deps" : liba
            }
      },

} );

shim can also be used to define the dependencies of AMD modules . So that will works except deps expects an array.

So try this

   shim: {
        backbone: {
              deps: [ "underscore", "jquery" ],
              exports: "Backbone"  
        }, 
        underscore: {
            exports: '_' 
        }, 
        libb: {
            deps : ["liba"]
        }
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM