2014-02-12 116 views
0

我不明白如何使用CommonJS模块加载外部资源。使用CommonJS加载外部资源

RequireJS提供垫片CONFIGS像:

require.config({ 
    shim: { 
     'facebook' : { 
      export: 'FB' 
     } 
    }, 
    paths: { 
     'facebook': '//connect.facebook.net/en_US/all/debug' 
    } 
}); 

我怎样才能做同样的CommonJS的?

回答

1

唯一的解决办法,我发现用普通JS(不CommonJS的)技术:

function loadFacebook(callback) { 
    if (typeof(FB) == 'undefined') { 
     jQuery.getScript('http://connect.facebook.net/en_US/all.js'); 
     jQuery.ajax({ 
      type: "GET", 
      url: "http://connect.facebook.net/en_US/all.js", 
      success: callback, 
      dataType: "script", 
      cache: true 
     }); 
    } 
    else { 
     callback(); 
    } 
} 

我惊讶的是CommonJS的没有定义任何specifaction加载外部资源。