2012-12-03 70 views
-1

我有如下應用結構:無法配置Require.js的baseUrl

+ project 
    + app 
    + script 
    + vendors 
     + backbone 
     + underscore 
     - require.js 
     - require.config.js 
    package.json 

我一直在使用jam.js安裝了所有的依賴。該package.json是看起來是這樣的:

{ 
    "name": "Project", 
    "jam": { 
      "packageDir": "app/scripts/vendor", 
     "baseUrl": "app", 
     "dependencies": { 
       "backbone": null 
     } 
    } 
} 

的的baseUrl設置爲app文件夾,如果我從 localhost/project/app運行我的應用程序它的工作就好了。但最終在後端我的應用程序index.html被包含在一個PHP網頁等等所有模塊的網址被打破,例如:

GET http://builder1.localhost/user/scripts/vendor/require.js 404 (Not Found) 

,而不是裝載:

localhost/project/app/scripts/vendor/require.js 

我如何配置'baseUrl'因此它會知道我已通過http://builder1.localhost/user/加載?

回答

0

你進入腳本(通過require.js加載的第一個腳本)應該有類似以下

require.config({ 
    baseUrl: "/another/path", 
    paths: { 
     "some": "some/v1.0" 
    }, 
    waitSeconds: 15 
}); 
require(["some/module", "my/module", "a.js", "b.js"], 
    function(someModule, myModule) { 
     //This function will be called when all the dependencies 
     //listed above are loaded. Note that this function could 
     //be called before the page is loaded. 
     //This callback is optional. 
    } 
); 

即從那裏文檔直取東西。仔細檢查你的代碼。如果它的絕對路徑而不是相對的,則基本URL更好。