admin管理员组文章数量:1336632
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?
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?
Share Improve this question asked Apr 4, 2014 at 14:01 Vlad TsepelevVlad Tsepelev 2,0561 gold badge21 silver badges32 bronze badges2 Answers
Reset to default 7If you give multiple configurations to RequireJS, it will bine 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 bined 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.
Louis' answer is right, but just a note, it is possible to read from multiple configs when using the r.js
optimizer. According to the example build file you can pass an array of values to the mainConfigFile, with the latter taking precedence over the former.
本文标签: javascriptHow to extend configs with RequireJSStack Overflow
版权声明:本文标题:javascript - How to extend configs with RequireJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742413024a2470166.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论