jamesknelson / gulp-rev-replace

Rewrite occurences of filenames which have been renamed by gulp-rev
MIT License
389 stars 62 forks source link

File names not replaced if useref compiles to a subdirectory #1

Closed uselesscode closed 10 years ago

uselesscode commented 10 years ago

When using gulp-useref to combine files if you put the combined file in a subdirectory, gulp-rev will rename the files and they will be placed in the subdirectory but gulp-rev-replace will not replace the file names in the HTML file.

This will work:

<!-- build:css normalize.css -->
  <link rel="stylesheet" href="css/normalize.css">
<!-- endbuild -->

But this will not:

<!-- build:css css/style.css -->
  <link rel="stylesheet" href="css/style.css">
<!-- endbuild -->

The final HTML produced would look like this:

<link rel="stylesheet" href="normalize-66961048.css"/>
<link rel="stylesheet" href="css/style.css"/>
sesponda commented 10 years ago

I confirm this. I believe the problem relies on the fact that the search and replace code in the plugin uses the file path in the search expression. If you are on Windows, this means "css\style.css", which will fail because the HTML has "css/style.css".

I've temporarily fixed this just adding .replace(path.separator,'/') to line 8 to normalize the separator, but this assumes that no one will be using windows-style paths o their html urls (it's a fair assumption, I believe).

@jamesknelson I will create a pull request, however I'm not sure if this is the best possible fix (I'm just starting with NodeJS / Gulp). Feel free to ignore the pull if there is a better solution.

yuri-karadzhov commented 10 years ago

+1

kasperisager commented 10 years ago

:+1:

jamesknelson commented 10 years ago

Can somebody confirm for me that merging #5 has fixed this? I'd happily merge a test for it as well...