Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access configuration of Require.js

I try to get the baseUrl configuration of Require.js inside a module, but I can't find where it is stored.

define([], function() {   // Here I'd like to access the `baseUrl` require.js is using   var baseUrl = requirejs.config().baseUrl; }); 

In my case, the baseUrl is set up by Require.js using the data-main attribute of the script file.

I know I can request module to access the config attributes (e.g. define(['module'])), but I can't find how to access the higher level of configuration option.

like image 769
Simon Boudrias Avatar asked Dec 21 '12 20:12

Simon Boudrias


People also ask

How do I use require config?

RequireJS can be initialized by passing the main configuration in the HTML template through the data-main attribute. It is used by RequireJS to know which module to load in your application. To include the Require. js file, you need to add the script tag in the html file.

What is require () in JavaScript?

1) require() In NodeJS, require() is a built-in function to include external modules that exist in separate files. require() statement basically reads a JavaScript file, executes it, and then proceeds to return the export object.

What is RequireJS config JS?

RequireJS is a JavaScript file and module loader. It improves perceived page load times because it allows JavaScript to load in the background. In particular, it enables asynchronous JavaScript loading.

Can I use require in JS file?

The require() method is used to load and cache JavaScript modules. So, if you want to load a local, relative JavaScript module into a Node. js application, you can simply use the require() method.


1 Answers

You can also reach the config into:

requirejs.s.contexts._.config  

to inspect the config object directly.

https://groups.google.com/forum/#!topic/requirejs/Hf-qNmM0ceI

like image 139
xdemocle Avatar answered Sep 21 '22 08:09

xdemocle