vbenjs / vite-plugin-imagemin

A vite plugin for compressing image assets.
MIT License
212 stars 28 forks source link

vite-plugin-legacy causes plugin to run twice on same assets #2

Closed naranjamecanica closed 3 years ago

naranjamecanica commented 3 years ago

I'm using https://github.com/vitejs/vite/tree/main/packages/plugin-legacy in my build setup to support older browsers and this causes to trigger the imagemin compression of images to run twice.

Thanks for the great plugin!

anncwb commented 3 years ago

Sorry, I just saw it. Let me see

anncwb commented 3 years ago

Can give me reproduction?I can't reproduce it

naranjamecanica commented 3 years ago

Sure, after the weekend I'll try to isolate it for you.

engram-design commented 3 years ago

This seems to be happening to me, and I believe you can guard against it in your writeBundle() with something like:

async writeBundle(options, bundle) {
    if (options.chunkFileNames.includes('-legacy')) {
        return;
    }

Although that's quick-and-dirty. I imagine you can change the name of the chunk to not always be legacy, so it's likely not foolproof, but maybe a start...