How to set default baseUrl

I use RequireJS and all of my modules are in /payloads/backend/application .

those.

 /payloads/backend/application/blog/newPost.js /payloads/backend/application/blog/models/category.js 

Whenever I use require() , I must point baseUrl in the object configuration:

 require({baseUrl: "/payloads/backend/application"}, ["blog/widgets/categories"], function(widget){ // do some stuff with widget }); 

I tried adding this to my <head> :

 <script type="text/javascript"> var require = { baseUrl: "/payloads/backend/application" }; </script> 

What does not help ...

I tried to temporarily move require.js to the application folder, which didn't help either.

How can I specify baseUrl by default?

+4
source share
1 answer

Can you show how you indicate that the order of the inline request requires calling above with a script tag to load require.js? With RequireJS 0.24.0 and later, 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 use the main data attribute (recommended), and main.js is already in the "apps" directory, then everything should work out: baseUrl should be automatically installed in the application 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 higher.

More error information would also help: is it still using baseUrl relative to the page? Is there any error in the console? Checking the Net or Resources panel in the browser’s web developer tools will show which file paths were used.

+6
source

Source: https://habr.com/ru/post/1346672/


All Articles