JCraine
JCraine

Reputation: 1395

Rewrite image paths in Grunt

I'm searching for a "catch-all" Grunt task to rewrite my html's image paths based on the production or dev environment. I've looked into usemin and filerev - but I'm having trouble understanding what exactly to do.

Is there anything I can use to change the following...

<img src="/img/template/banner.jpg" />

to this:

<img src"/some-other-path-here/banner.jpg />

Cheers,

Upvotes: 2

Views: 1287

Answers (2)

tomerz
tomerz

Reputation: 209

it can be done in usemin

patterns: {
                js: [
                    [/(img\/.*?\.(?:gif|jpeg|jpg|png|webp|svg))/gm,'Update the JS to reference our revved images',function(match){
return .... <-- you can replace it to whatever you want here.

}

Upvotes: 1

xiwcx
xiwcx

Reputation: 227

Grunt-usemin isn't the task for this particular job, it is meant to automate the concatenation, minification, and revving of your scripts and styles in a single step. There are several "CDN" tasks that will help you with changing relative paths:

Upvotes: 4

Related Questions