usemin + filerev results in src prefixed with a dot (as in "current directory")
Hello,
I'm using both usemin and filerev, both wonderful. (Except usemin's docs, haha.)
The paths generated for files are prefixed with a dot, as in:
<link rel="stylesheet" href="./style.abcdef.css"/>
<script src="./script.abcdef.js"></script>
I checked grunt.filerev.summary var and paths are OK there.
It's usemin that adds the dot.
Any idea why that happens and if it can be removed?
./ just mean it's a relative path. It's the same as without.
So if it's the same, but in more chars + it looks ugly, why add it?
It's not the same as without: ./ is relative to current directory while / is absolute.
I'm trying to remove the dot, not both.
Relative path doesn't work with webapps that change URL. I need the dot to go away so that it's an absolute path.
Thus, the same file is referenced from:
example.org/index.html
and
example.org/people/
for example.
It's actually the combo with filerev that breaks the path.
Without filerev, the ./ prefix is not added.
So, without filerev. the output would be something like this:
<link rel="stylesheet" href="/style.css"/>
With filerev, the output is this:
<link rel="stylesheet" href="./style.abcdef.css"/>
The first one references the file absolutely, the second relatively. The second one breaks for apps that make use of history manipulation.
Please re-open.
The issue is inside the revvedfinder.js file.
path.dirname(file); returns . which you add in front of the path.
https://github.com/yeoman/grunt-usemin/blob/dbbee1e14b03bfe01c38a303a76f188d4b9d3beb/lib/revvedfinder.js#L27 ~ and ~ https://github.com/yeoman/grunt-usemin/blob/dbbee1e14b03bfe01c38a303a76f188d4b9d3beb/lib/revvedfinder.js#L53
The first one (L27) is the one which affects grunt-filerev (getCandidatesFromMapping() method).
I don't know what the best way to fix this is.
@sindresorhus * ping *
https://github.com/yeoman/grunt-usemin/pull/421
Thank you, @sindresorhus.
+1