我正在使用webpack,它使用正则表达式将文件传递给装载器。我想排除测试文件,在这里测试文件以.test.js
结尾。因此,我正在寻找一个正则表达式,它匹配index.js
但不匹配index.test.js
。
我尝试使用负回顾断言:
/(?<!\.test)\.js$/
但是它说表达式无效。
SyntaxError: Invalid regular expression: /(?<!\.test)\.js$/: Invalid group
示例文件名:
index.js // <-- should match
index.test.js // <-- should not match
component.js // <-- should match
component.test.js // <-- should not match
function (path) { return path.endsWith('.js') && !path.endsWith('test.js')}
不过我可能会把它和其他打包工具混淆了。 - Karl-Johan Sjögren