Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to address images in handlebars templates if the images are optimized with grunt-contrib-imagemin

I have created an ember app with yeoman and generator-ember.

yo ember

I have placed my handlebars templates in app/templates and the images in app/images. if I run

grunt server

everything looks fine. If I run

grunt server:dist

everything looks fine instead of the images I have addressed in my handlebars templates. It seems that the task imagemin or something else renames the images from something like images/map.jpg to something like images/667de70e.map.jpg. The img tags in my index.html file are corrected. But the img tags in my handlebars files like templates/map.hbs are still addressing the old path images/map.jpg.

How can I fix the path problem in my handlebars files? Is there a helper?

like image 467
koalabruder Avatar asked May 09 '13 07:05

koalabruder


2 Answers

This is due to the rev task defined within Gruntfile.js. Don't think there's currently an straightforward solution for this, so I just comment out the line for renaming images:

// Gruntfile.js
// ...
rev: {
    dist: {
        files: {
            src: [
                '<%= yeoman.dist %>/scripts/{,*/}*.js',
                '<%= yeoman.dist %>/styles/{,*/}*.css',
                // '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp}',
                '<%= yeoman.dist %>/styles/fonts/*'
            ]
        }
    }
}
like image 162
Panagiotis Panagi Avatar answered Nov 16 '22 16:11

Panagiotis Panagi


Best explanation I've found is here: https://stackoverflow.com/a/20433339/314631

In short, the grunt rev task works as expected for css background images but not for img src attr.

like image 29
Luke W Avatar answered Nov 16 '22 16:11

Luke W