最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set default baseUrl - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 6

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 (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.

发布评论

评论列表(0)

  1. 暂无评论