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>
你想要./到路徑 –
非常感謝。我之前嘗試過,它沒有工作,也許緩存沒有更新或什麼。現在它似乎工作。謝謝一堆。如果您想將評論轉換爲答案,我會接受它 – dchhetri
並完成。請享用! –