admin管理员组文章数量:1334342
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?
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?
Share Improve this question edited Apr 5, 2011 at 6:29 Cobby asked Apr 5, 2011 at 6:21 CobbyCobby 5,4544 gold badges29 silver badges41 bronze badges1 Answer
Reset to default 6Can 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:
<script type="text/javascript">
var require = {
baseUrl: "/payloads/backend/application"
};
</script>
<script src="path/to/require.js"></script>
<script>require(["blog/widgets/categories"], function () {}</script>
If you are using the data-main attribute (remended), 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:
<script data-main="/payloads/backend/application/main.js" src="path/to/require.js"></script>
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.
本文标签: javascriptHow to set default baseUrlStack Overflow
版权声明:本文标题:javascript - How to set default baseUrl - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742368457a2461758.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论