Webpack 网页包加载器中的正则表达式排除/包含配置不';行不通

Webpack 网页包加载器中的正则表达式排除/包含配置不';行不通,webpack,Webpack,除了我的应用程序之外,我正在尝试将babel loader应用到特定的模块模式,比如foo.,在节点模块下 应像往常一样跳过节点_modules下的其他模块。首先,我尝试使用消极的前瞻性,但没有成功: { test: /\.js$/, exclude: [ /node_modules\/(?!foo).*/ ], loader: 'babel-loader', query: { ... } }, 然后我分成了两台装载机,也没有工作: { test:

除了我的应用程序之外,我正在尝试将
babel loader
应用到特定的模块模式,比如foo.,在节点模块下

应像往常一样跳过节点_modules
下的其他模块。首先,我尝试使用消极的前瞻性,但没有成功:

{
  test: /\.js$/,
  exclude: [
    /node_modules\/(?!foo).*/
  ],
  loader: 'babel-loader',
  query: {
    ...
  }
}, 
然后我分成了两台装载机,也没有工作:

{
  test: /\.js$/,
  exclude: [
    path.resolve(_path, "node_modules")
  ],
  loader: 'babel-loader',
  query: {
    ...
  }
}, 
{
  test: /\.js$/,
  include: [
    /node_modules\/foo.*/
  ],
  loader: 'babel-loader',
  query: {
    ...
  }
}
但是,如果我使用字符串而不是正则表达式,则它适用于一个文件夹:

include: [
  path.resolve(_path, "node_modules/foo")
],
这向我表明,Regex没有按预期工作


有人在
Include/Exclude
字段中使用了RegEx吗?

结果是我使用的Windows中的路径分隔符问题。以下消极前瞻语法有效,且与操作系统无关:

new RegExp('node_modules\\'+path.sep+'(?!foo).*')

另一种选择是使用或作为操作系统特定的路径分隔符:
。。。排除:[/node\u模块(?!(\/\\\)foo)/]…