2013-08-05 33 views
1

我的結構看起來像這樣:Require.js - 如何相對於加載一個模塊目錄

  • 的index.html
  • main.js #holds的configs.path和configs.shim
    • 的jquery.js
    • require.js
    • Backbone.js的
    • undersc ore.js
  • 模塊
    • 應用
      • main.js #want在./views/app.js這裏
      • 視圖加載
        • app.js

所以在/modules/app/main.js,我想在/modules/app/views/app.js加載,但具有的問題

這裏是/模塊/應用程序/主。 JS

define(['views/app'],function(App){ 
console.log('app main') 
//var app = new App(); 
}) 

控制檯錯誤消息我得到的就是與路徑GitProjects/GameApp/views/app.js

如何獲得它加載相對內部模塊失敗了嗎?

這裏是./main.js持有的CONFIGS

require.config({ 
    paths: { 
     jquery: './libs/jquery-2.0.3', 
     underscore: './libs/underscore', 
     backbone: './libs/backbone' 
    }, 
    shim: { 
     "underscore": { 
      exports: '_' 
     }, 
     "backbone": { 
      deps: ["underscore", "jquery"], 
      exports: "Backbone" 
     } 
    } 
}); 

,這裏的文件是我的index.html

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8"> 
     <title>Stop Game App</title> 
     <script src="./libs/require.js" data-main='./main'></script> 
    </head> 
    <body> 
     <div id="app"></div> 
     <script> 
     require(['./modules/app/main'],function(){ 
       console.log('main') 
      }) 
     </script> 
    </body> 
</html> 
+1

你想要./到路徑 –

+0

非常感謝。我之前嘗試過,它沒有工作,也許緩存沒有更新或什麼。現在它似乎工作。謝謝一堆。如果您想將評論轉換爲答案,我會接受它 – dchhetri

+0

並完成。請享用! –

回答

2

你只需要設置路徑 「./」 和是相對的。這裏的所有都是它的。

相關問題