Search code examples
gruntjsgrunt-contrib-imagemin

Grunt imagemin for multiple locations


I am trying to add Grunts imagemin plugin and it is working fine if I want to work in one directory only. However I have a multilingual site and therefore I have separate image directories for both English and French images. Is there a way to apply this plugin so it watches both directories and sends the compressed images to different destinations?

Here is what I have at the moment as the standard implementation:

imagemin: {
    dymanic: {
        files: [{
            expand: true,
            cwd: 'English/assets/img/',
            src: ['**/*.{png,jpg,gif}'],
            dest: 'English/assets/img/build/'
        }]
    }
}

What I need to do is also add a French location in the 'cwd' field and a French destination in the 'dest' field but I don't know how to add this to the existing code.

Thanks


Solution

  • I found the simple answer in case anyone else is having this issue. I simply change dynamic to a unique name and then copied the code again and gave it a new name. Example below:

    imagemin: {
        English: {
            files: [{
                expand: true,
                cwd: 'English/assets/img/',
                src: ['**/*.{png,jpg,gif}'],
                dest: 'English/assets/img/build/'
            }]
        },
        French: {
            files: [{
                expand: true,
                cwd: 'French/assets/img/',
                src: ['**/*.{png,jpg,gif}'],
                dest: 'French/assets/img/build/'
            }]
        }
    }
    

    If anyone knows of a shorter way to achieve this then please let me know. Otherwise this appears to work exactly as I need it to.