-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite of JavaScript URL's #106
Comments
@smysnk any advice here? |
@niftylettuce, the API leaves a bit to be desired but you can use the annotator and replacer options. The first lets you split up your sources into annotated fragments. In the replacer function you can choose to not replace a reference for a particular fragment. See https://github.com/smysnk/gulp-rev-all#annotater--replacer |
@circlingthesun Can you provide an example of how I'd prevent a file from replacing references to itself? Shouldn't this be standard? Why do JavaScript URL references get replaced that don't even have extensions? |
(e.g. I resolved this issue by appending a trailing |
CommonJS and AMD allow one to reference modules without an extension. So that's why extensionless references are targeted. You should be able to avoid self references with something like this: options.annotator = function(contents, path) {
var fragments = [{'contents': contents, 'path': path}];
return fragments;
};
options.replacer = function(fragment, replaceRegExp, newReference, referencedFile) {
if(fragment.path === referencedFile.revPathOriginal){
return;
}
fragment.contents = fragment.contents.replace(replaceRegExp, '$1' + newReference + '$3$4');
}; or avoid extensionless replacements like so: options.annotator = function(contents, path) {
var fragments = [{'contents': contents}];
return fragments;
};
options.replacer = function(fragment, replaceRegExp, newReference, referencedFile) {
if(referencedFile.revFilenameExtOriginal === '.js' && !newReference.match(/\.js$/)){
return;
}
fragment.contents = fragment.contents.replace(replaceRegExp, '$1' + newReference + '$3$4');
}; |
hi @circlingthesun, thanks a lot for posting the options! I have been trying to avoid extensionless replacements, and it seems like Thanks, |
@circlingthesun I think you should prevent a file from replacing instances of references to itself as a base for this project, otherwise you need to make it clear in the documentation to append trailing forward slashes. This is a very common scenario and it is a definite bug. Please consider my request to publish a patch, thank you! |
+1 |
@sixinli try this:
because @circlingthesun can you post a officail code to solve this problem? |
e.g. AJAX request, this URL gets rewritten by a file with the same name as the path of the request
before:
after:
(and ofc
/checkout.js
exists so that's why it conflicts)The text was updated successfully, but these errors were encountered: