简体   繁体   中英

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

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.

you don't need use: dynamic {} or static {}, you can remove English and french will works perfect.

see: Grunt imagemin running but not minifying

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM