0

我在 gulp 配方中使用 RequireJS 优化器来编译和连接我的模块,但是冗余的第 3 方库文件(如 bower.json 和 *.nuspec 文件)被复制到我的输出目录中。

我已经成功地使用以下表达式在 requirejs.optimize 选项对象中使用 fileExclusionRegExp 排除了完整目录:

/^\.|^styles$|^templates$|^tests$|^webdriver$/

但是,我无法弄清楚如何排除.js文件扩展名以外的所有内容。我可以使用以下内容:

/^\.|.json$|.nuspec$|^styles$|^templates$|^tests$|^webdriver$/

排除特定扩展,但如果稍后出现新类型,我将不得不注意然后更改正则表达式。此外,随着时间的推移,正则表达式可能会变得不守规矩且难以维护。我尝试使用以下表达式:

/^\.|!js$|^styles$|^templates$|^tests$|^webdriver$/

/^\.|!.js$|^styles$|^templates$|^tests$|^webdriver$/

/^\.|^.js$|^styles$|^templates$|^tests$|^webdriver$/

/^\.|[^.js$]|^styles$|^templates$|^tests$|^webdriver$/

/^\.|[^.js]$|^styles$|^templates$|^tests$|^webdriver$/

结果的范围从无所事事(前 3 个,到破坏构建,最后 2 个),任何人都可以提供任何帮助,我们将不胜感激。

谢谢

4

1 回答 1

0

试试这个正则表达式:

^\.|\.(json|nuspec)$|^(styles|templates|tests|webdriver)$

正则表达式可视化

于 2015-01-22T14:33:45.487 回答