Question

I thought I'd be able to expose my JS library to Require.js, and make it dependent on jQuery, Backbone, and Underscore, with the following code:

 } else if (typeof define === 'function' && define.amd) {

  define(['backbone', 'jquery', 'underscore'], function(Backbone, $, _) {
      return factory(root, Backbone, $, _);
  });

where factory is a function that returns my library. That seems ok, except that the module name "backbone" appears to be hard-coded to the filesystem path "{Require root}/backbone". Even if I define a path in my Require config before requiring the library:

'backbone': '/some/other/path/backbone'

my browser still gives me an error:

GET http://localhost:8000/js/backbone.js 404 (NOT FOUND)

Can anyone explain how I can define "this library depends on Backbone" without saying "this library requires exactly {root}/backbone.js"?

Était-ce utile?

La solution

That is exactly what Backbone does so I'm not sure why you're having problems. Can you post the code of how you're requiring this library and where you're defining your require config?

if (typeof define === 'function' && define.amd) {
  define(['underscore', 'jquery', 'exports'], function(_, $, exports) {
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top