RegEx error in Webpack exclude / include loader not working

I am trying to apply babel-loader to a specific module template like foo. * , under node_modules in addition to my application.

Other modules under node_modules should be skipped as usual. At first I tried to use a negative look, but did not work:

 { test: /\.js$/, exclude: [ /node_modules\/(?!foo).*/ ], loader: 'babel-loader', query: { ... } }, 

Then I split into two bootloaders and didn't work:

 { test: /\.js$/, exclude: [ path.resolve(_path, "node_modules") ], loader: 'babel-loader', query: { ... } }, { test: /\.js$/, include: [ /node_modules\/foo.*/ ], loader: 'babel-loader', query: { ... } } 

However, if I use a string instead of RegEx, it works for a single folder:

 include: [ path.resolve(_path, "node_modules/foo") ], 

This indicates that Regex is not working as expected.

Has anyone got a RegEx working in an Include/Exclude field?

+6
source share
1 answer

Turns out this is a Windows path separator issue that I use. The following negative lookahead syntax works and is agnostic:

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

All Articles