javascript - How to extend configs with RequireJS - Stack Overflow

Im using RequireJS for my coding. I have one source base, but have few different frontends.These front

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 badges
Add a ment  | 

2 Answers 2

Reset to default 7

If 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742413025a4439192.html

相关推荐

  • javascript - How to extend configs with RequireJS - Stack Overflow

    Im using RequireJS for my coding. I have one source base, but have few different frontends.These front

    10小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信