Javascript Require.js——如何相对于模块目录加载
我的结构是这样的:Javascript Require.js——如何相对于模块目录加载,javascript,requirejs,dynamic-script-loading,Javascript,Requirejs,Dynamic Script Loading,我的结构是这样的: index.html main.js#保存configs.path和configs.shim 自由基 jquery.js require.js backbone.js 下划线.js 模块 应用程序 main.js#要在此处加载。/views/app.js 观点 app.js 所以在/modules/app/main.js中,我想加载/modules/app/views/app.js,但有问题 这里是/modules/app/main.js define([
- index.html
- main.js#保存configs.path和configs.shim
- 自由基
- jquery.js
- require.js
- backbone.js
- 下划线.js
- 模块
- 应用程序
- main.js#要在此处加载。/views/app.js
- 观点
- app.js
- 应用程序
define(['views/app'],function(App){
console.log('app main')
//var app = new App();
})
我收到的控制台错误消息是get failed,路径为GitProjects/GameApp/views/app.js
如何让它相对地装入模块内部
下面是保存配置的文件/main.js
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>
停止游戏应用程序
需要(['./modules/app/main'],函数(){
console.log('main')
})
您只需将路径设置为“/”并保持相对。这就是它的全部。你想要。/到pathnice谢谢。我以前试过,但没用,可能是缓存没更新什么的。现在它似乎起作用了。非常感谢。如果你想把评论转换成答案,我会接受的