문제

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"?

도움이 되었습니까?

해결책

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) {
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top