如何设置默认baseUrl
我正在使用 RequireJS,我的所有模块都位于 /payloads/backend/application
中。
即,
/payloads/backend/application/blog/newPost.js
/payloads/backend/application/blog/models/category.js
每当我使用 require()
时,我都必须在配置对象中指定 baseUrl:
require({baseUrl: "/payloads/backend/application"}, ["blog/widgets/categories"], function(widget){
// do some stuff with widget
});
我尝试将其添加到我的 中:
<script type="text/javascript">
var require = {
baseUrl: "/payloads/backend/application"
};
</script>
这没有帮助。 ..
我尝试暂时将 require.js 移动到应用程序文件夹,但这也没有帮助。
如何指定默认的baseUrl?
I'm using RequireJS, and all my modules reside in /payloads/backend/application
.
I.e.
/payloads/backend/application/blog/newPost.js
/payloads/backend/application/blog/models/category.js
Whenever I use require()
I have to specify the baseUrl in a configuration object:
require({baseUrl: "/payloads/backend/application"}, ["blog/widgets/categories"], function(widget){
// do some stuff with widget
});
I have tried adding this into my <head>
:
<script type="text/javascript">
var require = {
baseUrl: "/payloads/backend/application"
};
</script>
Which doesn't help...
I tried temporarily moving require.js to the application folder which didn't helper either.
How can I specify a default baseUrl?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能否展示如何使用脚本标记指定上面的内联 require 调用的顺序来加载 require.js?对于 RequireJS 0.24.0 及更高版本,这应该可以工作:
如果您使用 data-main 属性(推荐),并且 main.js 已经在“applications”目录中,那么一切都应该解决:应该设置 baseUrl自动到应用程序目录:
以上仅适用于 RequireJS 0.24.0 及更高版本。
有关错误的更多信息也会有所帮助:它是否仍然使用相对于页面的 baseUrl?控制台中是否抛出某种错误?检查浏览器的 Web 开发人员工具中的“网络”或“资源”面板将显示使用的文件路径。
Can you show how you are specifying the order of the inline require call above with the script tag to load require.js? With RequireJS 0.24.0 and greater, this should work:
If you are using the data-main attribute (recommended), and main.js is already in the "applications" directory, then it should all work out: the baseUrl should be set automatically to the applications directory:
The above only works with RequireJS 0.24.0 and greater.
More information about the error would help too: does it still use a baseUrl relative to the page? Is there some kind of error thrown in the console? Checking the Net or Resources panel in the browser's web developer tools will show what file paths were used.