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

ng-src get ignored to replace image source

Open nobalmohan opened this issue 10 years ago • 8 comments

I use ng-src for angular UI bootstrap carousel and found that ng-src in img tag ( img ng-src=" " ) get ignored by usemin to replace its respective compressed images.

Though angular UI bootstrap carousel works with "src". Reporting this use-case.

nobalmohan avatar Dec 11 '14 09:12 nobalmohan

That's a non-standard attribute. It would have to be added here: https://github.com/yeoman/grunt-usemin/blob/547310075dbf1f33ab79e756a2c127b0602d1155/lib/fileprocessor.js#L8

PR welcome (with unit test).

sindresorhus avatar Dec 15 '14 05:12 sindresorhus

I tried some regex but no luck

pasupulaphani avatar Feb 10 '15 04:02 pasupulaphani

@pasupulaphani you should be able to tell usemin by using patterns options.

usemin: {
  js: '*.js',
  options: {
    patterns: {
      js: [
        [/<img[^\>]*[^\>\S]+ng-src=['"]([^'"\)#]+)(#.+)?["']/gm, 'Update the HTML with non standard ng-src attribute on img']
      ]
    }
  }
}

stephanebachelier avatar Feb 21 '15 23:02 stephanebachelier

Tagging as doc as it should be added to a documentation

stephanebachelier avatar Feb 22 '15 00:02 stephanebachelier

@pasupulaphani coming back to you with the attribute ng-src.

Have you tried the configuration I gave you ?

Digging into AngularJS doc I've found that your are using ngSrc directive. What I understand is that your url might be dynamic URL, something like:

<img ng-src="http://www.gravatar.com/avatar/{{hash}}" alt="Description" />

When AngularJS will replace the hash with it's value, the request will be fetched.

I'll end with a question: is usemin process running while the url is known or while still parameterized ?

stephanebachelier avatar Apr 15 '15 22:04 stephanebachelier

Using ng-src for static images is very common in the Angular world. In addition, libraries like Angular Material commonly use a directive attribute like md-svg-src as the source of the svg image. The ideal fix for this is to have a config that allows the user to input the tags to look for without having to write (in my opinion) complicated regex expressions that have been shared in various SO posts. Another option is to read all the image names in the images directory structure and do a direct search and replace with the renamed version.

This issue is a real blocker for Angular Grunt users as I personally have spent many hours tracking down what is actually causing my images to not load.

chriseyhorn avatar Sep 26 '15 20:09 chriseyhorn

ng-source still gets ignored, even with the custom pattern suggested by stephanebachelier. Btw, it should be an html pattern an not js.

leolux avatar Nov 19 '15 11:11 leolux

This is still happening to angular-material elements, md-svg-src="assets/images/chat.svg", for example.:

Darksoulsong avatar Aug 08 '16 19:08 Darksoulsong