JonasKruckenberg / imagetools

Load and transform images using a toolbox :toolbox: of custom import directives!
MIT License
937 stars 59 forks source link

The plugin processes images with ?raw and ?url queries when it shouldn't #748

Open didoin opened 1 month ago

didoin commented 1 month ago

I’d like to report a minor bug. When I import images using only the ?raw or ?url queries, the plugin processes them when it shouldn’t. As a result, the asset build generates images in .png format instead of preserving the original file format. It seems that if the format is not specified, the plugin defaults to converting images to .png.

According to the Vite documentation on Static Asset Handling I can import an image using these arguments to determine whether to receive the asset's URL or a string containing the image content, which is particularly useful for .svg files.

This issue can be easily circumvented with the following configuration:

// vite.config.js
export default defineConfig({
    plugins: [
      imagetools({
        exclude: [
          'public/**/*',
          /\?(url|raw)$/, // FIX bug ?raw & ?url
        ],
    ],
});

However, I think it is appropriate to apply a FIX directly in the plugin code, since the ?url and ?raw queries are vite-specific features and should be handled automatically by the plugin.

Thank you.

benmccann commented 1 month ago

Yeah. That sounds reasonable. PR welcome