r.js - excluding specific list of files

女生的网名这么多〃 提交于 2019-12-13 15:30:47

问题


Hello evryone,

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.

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?

Thanks in advance


回答1:


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 ".".

The default value is:

/^\./

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.

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$/

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.



来源:https://stackoverflow.com/questions/27898856/r-js-excluding-specific-list-of-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!