Im using RequireJS for my coding. I have one source base, but have few different frontends. These frontends should use different sets of modules, so I have to support few RequireJS configs, each for different product. Adding module to one config, cause adding it to few additional configs.
Is there way to inherit/extend RequireJS configs?
If you give multiple configurations to RequireJS, it will combine them. For instance if you first make this call:
require.config({
paths: {
foo: "path/to/foo",
bar: "path/to/bar"
}
});
And then this second call:
require.config({
paths: {
foo: "some/other/path/to/foo",
baz: "path/to/baz"
}
});
These two will be combined so that bar
still has the path defined in the first require.config
call. However, foo
will be overridden by the second config. And baz
won't be resolved as path/to/baz
until the 2nd config is read.
There are limitations however. For instance, you can give an array as a paths
setting for a specific module. For instance, foo: ["/some/path", "another/path"]
. RequireJS will try the paths in order when you require foo
. However, there is no method to tell RequireJS in a subsequent call to require.config
to take whatever array was set earlier and just add another value to the array. You'd have to give require.config
the whole array in a subsequent call.
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