r.js-排除文件的特​​定列表 [英] r.js - excluding specific list of files

查看:138
本文介绍了r.js-排除文件的特​​定列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆