Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

[Question] Configuring regex in usemin task to apply minifcation to srcset attribute #1385

Open
brunocasarotti opened this issue Jan 13, 2017 · 0 comments

Comments

@brunocasarotti
Copy link

brunocasarotti commented Jan 13, 2017

I have the following configuration in my gruntfile:

// Performs rewrites based on filerev and the useminPrepare configuration
    usemin: {
      html: ['<%= yeoman.dist %>/{,*/}*.html'],
      css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
      js: ['<%= yeoman.dist %>/scripts/{,*/}*.js'],
      options: {
        assetsDirs: [
          '<%= yeoman.dist %>',
          '<%= yeoman.dist %>/images',
          '<%= yeoman.dist %>/styles'
        ],
        patterns: {
          js: [[/(images\/[^''""]*\.(png|jpg|jpeg|gif|webp|svg))/g, 'Replacing references to images']]
        }
      }
    },

When I run my build task to dist it transforms this:

<img src="images/calculo.jpg" srcset="images/calculo.jpg 360w, images/calculo.jpg 830w" sizes="(min-width: 992px) 360px, calc(100vw - 30px)"
                        class="wp-post-image" alt="Cálculo Estrutural" width="360" height="180">

to this:
<img src="images/calculo.47c12a85.jpg" srcset="images/calculo.jpg 360w, images/calculo.jpg 830w" sizes="(min-width: 992px) 360px, calc(100vw - 30px)" class="wp-post-image" alt="Cálculo Estrutural" width="360" height="180">

How can I also apply the same pattern that was applied to the src attribute in the srcset attribute in order to produce the following code:
<img src="images/calculo.47c12a85.jpg" srcset="images/calculo.47c12a85.jpg 360w, images/calculo.47c12a85.jpg 830w" sizes="(min-width: 992px) 360px, calc(100vw - 30px)" class="wp-post-image" alt="Cálculo Estrutural" width="360" height="180">

@brunocasarotti brunocasarotti changed the title Configuring regex in usemin task to apply minifcation to srcset attribute [Question] Configuring regex in usemin task to apply minifcation to srcset attribute Jan 13, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant