R.js - excluding a specific list of files

Hi evryone,

I'm trying to find a way to make r.js not copy all files from my / lib / directory except (for example) jquery.js and require.js .

I am using the fileExclusionRegExp parameter to exclude all * .js files except the above.

 fileExclusionRegExp: '\/lib\/(?!jquery|require).*\.js'

      

But after optimizing, I can still see that other files have been copied as well.

Is there something I am doing wrong? Or a wrong regex?

Thank you in advance

+2


source to share


1 answer


The problem you are having is that you are trying to fileExclusionRegExp

match the entire file path, but r.js

only use it to check the base name of the files. You can do this from the parameter description 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 ".".

      

Default value:

/^\./

      



If it was to be tested against a full path, it will not be able to exclude files starting with a period if they are in a subdirectory. We are also confirming this behavior in this release .

If you only have one file named require.js

and one file named jquery.js

, you can traverse with this regex:

fileExclusionRegExp: /^(?!jquery|require).*\.js$/

      

Otherwise fileExclusionRegExp

not going to do that and you should use a build step to clean up your directory as suggested by the author of RequireJS in the issue report I mentioned above.

+1


source







All Articles