Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
didoin opened this issue Sep 26, 2024 · 1 comment
Open

Comments

@didoin
Copy link

didoin commented Sep 26, 2024

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
Copy link
Collaborator

Yeah. That sounds reasonable. PR welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants