benhoIIand / grunt-cache-bust

Cache bust static assets using content hashing
MIT License
265 stars 103 forks source link

References in Subfolders not getting updated #243

Open chibui opened 6 years ago

chibui commented 6 years ago

I can't seem to get references in subfolders to update with the hashed name.

My config is :

cacheBust: { 
            test: {
                options: {
                    deleteOriginals: true,
                    assets: ['**/**.{css,html}'],
                    baseDir: 'dist'
                },
                files: [{
                    expand: true,
                    cwd: 'dist',
                    src: ['**/*.{html, js}',]
                }]
            }
        }

My app structure prior to running task :

app|
---|dist|
--------|child.html
--------|child.css
--------|foo|
------------|foo.html
------------|foo.css
------------|bar|
----------------|bar.html
----------------|bar.css
--------|noop|
---------------|noop.html
---------------|noop.css

When I run the task, all the file are correctly renamed with the hash val. The issue is that with the exception of the reference in child.html being updated, none of the other references are updated.

foo.html

<!doctype html>
<html>
<head>
    <link href="foo.css" type="text/css" rel="stylesheet" />
</head>
<body>
<h2>FOO!!!</h2>
</body>
</html>

I've tried various configs but without any success. I've even tried to reference the source files directly.

files: [{
    expand: true,
    cwd: 'dist/',
    src: ['dist/foo/**/*.html', 'dist/noop/**/*.html']
 }]

and also

src: [ 'dist/foo/*.html', 'dist/noop/*.html']

Im using grunt-cache-bust v 1.7.0

Thanks in advance.

osamamaruf commented 6 years ago

+1 facing the same issue on grunt-cache-bust v 1.7.0. Any workarounds?

pankaj-arunsingh commented 5 years ago

+1 I faced the same issue. Seems like there is a PR https://github.com/hollandben/grunt-cache-bust/pull/245 which should fix it. We should wait for it to be merged soon.

Taelkir commented 5 years ago

Running Windows and having the same issue, but the code from the PR doesn't seem to solve it for me. Instead, in node_modules\grunt-cache-bust\tasks\cachebust.js I changed the loop at line 134 to start from 0 instead of 1.

Made my own PR at https://github.com/hollandben/grunt-cache-bust/pull/250 - hopefully this helps someone else.

dikaso commented 5 years ago

I can also confirm that #250 works as expected (Linux).