I'm currently integrating foreign code into our application. Part of the process, I must substitute one of their requirejs modules with ours.
Obviously I can't modify their code, otherwise I'd have to do the change at every update. What I can do is modify the main.js (data-main of requirejs).
Here is, roughly, what they have:
requirejs.config({
packages: [
'beerpong'
]
});
So they have this beerpong
package, with some modules in there. Among these modules, there is the beer.js
file. It can be required with a require('beerpong/beer')
.
Aside from this, I have my files, in a separate folder, say vodkapong/beersubstitute
. What I would like is that, whenever someone require('beerpong/beer')
, that requirejs actually serves him my vodkapong/beersubstitute
instead.
tl;dr: How can I remap an existing module to use my module instead?
PS: Sadly, we're not actually writing a beerpong game... One day maybe!
You could use the map option. It can remap an AMD module for a specific module or for all modules with the "*"
name. An example would be:
require.config({
map: {
"*": {
"beerpong/beer": "vodkapong/beersubstitute"
}
},
...
});
You can do something like this -
require.config({
paths: {
jquery_ui_scrollbar: 'libs/jquery/jquery.custom-scrollbar'
}
});
require(['dependency1', 'dependency2'], function (dep1, dep2) {
// code goes here
});
And in your define call you can do this -
define(['jquery_ui_scrollbar'], function(scrollbar) {});
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