How to set 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开发者_如何学编程?
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:
<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 (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:
<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.
精彩评论