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.
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With