I want to be able to inject extra paths, in a file different from the one which contains the config. Can this be done? A bonus question is whether I can directly access "config" variables.
I want to be able to inject extra paths, in a file different from the one which contains the config. Can this be done? A bonus question is whether I can directly access "config" variables.
Share Improve this question asked Sep 30, 2013 at 8:42 sabofsabof 8,1924 gold badges31 silver badges53 bronze badges 1 |1 Answer
Reset to default 18There is no problem with calling require.config
multiple times or from multiple places. You don't have to provide an entire set of configuration on subsequent calls. The new path mappings will be merged with existing ones.
For example, if you did this originally:
require.config({
paths: {
foomodule: 'libs/foo',
jquery: 'libs/jquery'
}
});
You could later do this to provide a different set of paths for jquery and/or to inject paths for a whole new module not present in the original config:
require.config({
paths: {
jquery: [ 'http://code.jquery.com/jquery-2.0.2', 'http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.2' ],
// note that foomodule not provided here but still keeps its original configuration
someothermodule: 'some/other/path'
}
});
Note, however, that if a module was already loaded based on the original config and you wanted to force it to reload from the new config you might have to call require.undef
Regarding the 2nd part of your question (reading the existing config information), I asked a question on this too and so far have not found a way to do it.
require.config()
has been run? – z-- Commented Sep 30, 2013 at 8:57