r.js-排除文件的特定列表 [英] r.js - excluding specific list of files
问题描述
您好evryone
我正在尝试寻找一种方法,以使 r.js 不会从我的/lib/目录中复制所有文件,除了(例如) jquery.js 和 require.js .
I'm trying to find a way to make the r.js not to copy all the files form my /lib/ directory except for (for example) jquery.js and require.js.
我正在使用 fileExclusionRegExp 选项排除上述所有* .js文件.
I'm using fileExclusionRegExp option to exclude all *.js files except for the above mentioned.
fileExclusionRegExp: '\/lib\/(?!jquery|require).*\.js'
但是在优化之后,我仍然可以看到其他文件也已被复制.
But after the optimization, I can still see that other files have been copied over too.
我在做错什么吗?还是正则表达式不正确?
Is there anything I'm doing wrong ? Or is the regex incorrect?
预先感谢
推荐答案
您遇到的问题是,您试图使fileExclusionRegExp
与文件的整个路径匹配,但是r.js
仅将其用于针对文件的基本名称进行测试.您可以从选项的描述及其默认值中推断出这一点. 说明说:
The problem you've run into is that you are trying to make fileExclusionRegExp
match the entire path of a file, but r.js
uses it only to test against the base name of files. You can infer this from the description of the option and its default value. The description says:
//When the optimizer copies files from the source location to the
//destination directory, it will skip directories and files that start
//with a ".".
默认值为:
/^\./
如果要针对完整路径进行测试,则如果它们位于子目录中,则将无法排除以句点开头的文件.我们还在此问题报告中找到了对此行为的确认.
If this were to be tested against a full path, it would not be able to exclude files that start with a period if they are in a subdirectory. We also find confirmation of this behavior in this issue report.
如果只有一个名为require.js
的文件和一个名为jquery.js
的文件,则可以使用此正则表达式:
If you have only one file named require.js
and one file named jquery.js
, then you can get by with this regexp:
fileExclusionRegExp: /^(?!jquery|require).*\.js$/
否则,fileExclusionRegExp
不会执行此操作,您应该使用构建步骤来清理目录,正如RequireJS的作者在上文提到的问题报告中所建议的那样.
Otherwise, fileExclusionRegExp
is not going to do it, and you should use a build step to clean your directory, as suggested by the author of RequireJS in the issue report I mention above.
这篇关于r.js-排除文件的特定列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!