grunt-usemin icon indicating copy to clipboard operation
grunt-usemin copied to clipboard

usemin + filerev results in src prefixed with a dot (as in "current directory")

Open Francisc opened this issue 12 years ago • 9 comments

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?

Francisc avatar Mar 21 '14 21:03 Francisc

./ just mean it's a relative path. It's the same as without.

sindresorhus avatar Jun 23 '14 18:06 sindresorhus

So if it's the same, but in more chars + it looks ugly, why add it?

Francisc avatar Jun 23 '14 21:06 Francisc

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.

Francisc avatar Aug 11 '14 09:08 Francisc

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.

Francisc avatar Aug 11 '14 09:08 Francisc

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.

Francisc avatar Aug 11 '14 12:08 Francisc

@sindresorhus * ping *

Francisc avatar Aug 13 '14 14:08 Francisc

https://github.com/yeoman/grunt-usemin/pull/421

sindresorhus avatar Aug 20 '14 23:08 sindresorhus

Thank you, @sindresorhus.

Francisc avatar Aug 21 '14 19:08 Francisc

+1

JobaDiniz avatar Aug 26 '14 17:08 JobaDiniz