如何在一个包含在循环中的require上使用ContextReplacementPlugin

psi*_*nny 10 webpack

我正在尝试使用ContextReplacementPlugin来解决此for循环中发生的动态需求:https://github.com/mongodb/js-bson/blob/master/lib/bson/index.js#L7-L24

这是代码:

[ './binary_parser'
  , './binary'
  , './code'
  , './map'
  , './db_ref'
  , './double'
  , './max_key'
  , './min_key'
  , './objectid'
  , './regexp'
  , './symbol'
  , './timestamp'
  , './long'].forEach(function (path) {
    var module = require(path);
    for (var i in module) {
        exports[i] = module[i];
    }
});
Run Code Online (Sandbox Code Playgroud)

我在构建源正则表达式时遇到了麻烦.与源匹配的路径似乎只是".".而且,当在这个循环中实际需要13个文件时,上下文插件似乎只被调用一次.可以使用ContextReplacementPlugin来解决此问题,还是应该尝试其他方法?