Luismahou / grunt-hashres

Hashes your js and css files and rename the <script> and <link> declarations that refer to them in your html/php/etc files.
MIT License
115 stars 41 forks source link

“Mapping” of multiple CSS files no longer works #38

Closed yellowled closed 10 years ago

yellowled commented 10 years ago

Using node.js 0.10.26, Grunt 0.4.4 and grunt-hashres 0.4.1 on OS X 10.9.2.

I include two stylesheets in HTML files to have a oldIE fallback in mobile first projects. This means that my hashres task has to rename/map two CSS files, which used to work fine.

Today I noticed that this is no longer the case – both CSS files are renamed properly, but both references in the HTML file are changed to the hash of the first stylesheet, i.e. for

<!--[if lte IE 8]>
    <link rel="stylesheet" href="styles/oldie.css">
<![endif]-->
<!--[if gt IE 8]><!-->
    <link rel="stylesheet" href="styles/master.css">
 <!--<![endif]-->

the output is

<!--[if lte IE 8]>
    <link rel="stylesheet" href="styles/fe3a671c.css">
<![endif]-->
<!--[if gt IE 8]><!-->
    <link rel="stylesheet" href="styles/fe3a671c.css">
 <!--<![endif]-->

which – of course – doesn't work.

Happy to provide further debug info/output, just give me very specific instructions what you need, please.

Luismahou commented 10 years ago

Did you run hashres twice without re-generating dist/*.html files? Last grunt-hashres release tries to be smart by identifying previously hashed references, and in your case, since your using {hash}.{ext} as a pattern, a second run wouldn't be able to determine that both references are different. Please run hashres using a clean version of dist/*.html.

yellowled commented 10 years ago

My deploy task includes contrib-clean which cleans out the entire dist/ directory before even running hashres. So yes, I did. :)

Also, further testing shows it doesn't seem to be related to the Grunt version. Have tested it with 0.4.2, 0.4.3 and 0.4.4. However, it does work in some test cases and doesn't work in others. Very weird. Any other ideas what to test/try? Change the hash pattern?

Luismahou commented 10 years ago

Try to change the pattern and let me know if it works.

Cheers

yellowled commented 10 years ago

It does in fact work if I use the default pattern ${hash}.${name}.cache.${ext} as well as with (apparently) any pattern including ${name}.

It does, by the way, not re-create the references if I run grunt hashres multiple times (using default in the first run, ${name}-${hash}.${ext} in the second) without cleaning dist first. But that's entirely acceptable, at least for me.

Thanks.