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.

我使用RequireJS进行编码。我有一个源基础,但几乎没有不同的前端。这些前端应该使用不同的模块集,因此我必须支持少量RequireJS配置,每个配置用于不同的产品。将模块添加到一个配置,导致将其添加到一些额外的配置。

Is there way to inherit/extend RequireJS configs?

有继承/扩展RequireJS配置的方法吗?

2 个解决方案

#1


5

If you give multiple configurations to RequireJS, it will combine them. For instance if you first make this call:

如果您为RequireJS提供多个配置,它将组合它们。例如,如果您第一次拨打此电话:

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.

这两个将合并,以便bar仍然具有在第一个require.config调用中定义的路径。但是,foo将被第二个配置覆盖。并且在读取第二个配置之前,baz不会被解析为path / to / baz。

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.

但是有一些限制。例如,您可以将数组作为特定模块的路径设置。例如,foo:[“/ some / path”,“another / path”]。当您需要foo时,RequireJS将按顺序尝试路径。但是,没有方法可以告诉RequireJS后续调用require.config来获取之前设置的任何数组,只需向该数组添加另一个值。您必须在后续调用中为require.config提供整个数组。

更多相关文章

  1. 在关联数组中移动元素[重复]
  2. JavaScript——数组(三)数组方法汇总
  3. 如何通过ajax将javascript数组传递给YII动作
  4. 在Javascript中将带有空格的字符串数组转换为小写,然后在Webkit中
  5. 返回指定时间段相同间隔数组
  6. JavaScript数组中的唯一计数,按计数排序
  7. Javascript sort()不适用于Chrome中超过10个对象的数组
  8. 获取JavaScript数组元素的最大长度
  9. 对多维数组中的列进行排序

随机推荐

  1. Android Service AIDL 远程调用服务 【简
  2. Android Debug certificate expired
  3. android实现服务器图片本地缓存
  4. Android EditText 光标控制,颜色修改,显示
  5. 利用 Android Keystore 系统 加密存储和
  6. Android笔记1
  7. Android TextView全属性
  8. Android中对Handle机制的理解
  9. android 中的 Broadcast 机制详解
  10. Android Studio开发基础之AutoCompleteTe