unplugin / unplugin-imagemin

📦 Compression Image compression plugin based on squoosh and sharp
199 stars 18 forks source link

beforeBundle not working #100

Open qlaffont opened 11 months ago

qlaffont commented 11 months ago

Steps to reproduce

imagemin({
        mode: 'sharp',
        beforeBundle: true,
        // Default configuration options for compressing different pictures
        compress: {
          jpg: {
            quality: 50,
          },
          jpeg: {
            quality: 70,
          },
          png: {
            quality: 70,
          },
          webp: {
            quality: 70,
          },
        },
      }),

What is expected?

able to optimize images

What is actually happening?

[unplugin-imagemin] 📦 📦 Process start with Mode sharp ▶ Not Found Image Module, if you want to use style with image style, such as "background-image" you can use "beforeBundle: false" in plugin config

System Info

- Linux (PopOS)

Any additional comments?

Working with solid-start : https://start.solidjs.com/getting-started/project-setup

If I use "beforeBundle" with false ->


[Error: ENOENT: no such file or directory, open '/home/quentin/Documents/dev/test/demo-ventes/dist/public/index.html'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/home/quentin/Documents/dev/test/demo-ventes/dist/public/index.html'
}
ErKeLost commented 11 months ago

I'll try.

ErKeLost commented 11 months ago

hi @qlaffont I have solved this problem and you can now install v0.5.15 to solve this error.

qlaffont commented 11 months ago

confirmed for beforeBundle: false but beforeBundle: true still say that no image module is found

ErKeLost commented 11 months ago

BeforeBundle is used to control true to convert images after the bundle is completed. False is for the vite load module, when we represent a new set of image resources, which may need to be integrated into a vite load mode. Now, when we run in load, we do not find the image resources, so we need to manually modify the source code after bundle. I tried earlier today that it can be compiled and compressed normally. Can you provide a warehouse that can be reproduced?

image

qlaffont commented 11 months ago

@ErKeLost after a long debugging period:

ErKeLost commented 11 months ago

I'll check what you said later.

qlaffont commented 10 months ago

Any update?

ErKeLost commented 10 months ago

I'll try to recreate it today. I'm sorry I've been a little busy lately.

ErKeLost commented 10 months ago

@qlaffont hi. The newly created solid ssr template seems to have some problems. Build will fail. The reason you said that the image resources are not stored in the dist directory may be because there is a problem with the output path acquisition of ssr.

BeforeBundle false is equivalent to manually managed output files, and when beforeBundle is true, we hijack the module operation flow of vite in the process of load hooks. In the end, these plug-ins get the ssr options inside vite, so there is no problem.

I may have to remove the beforeBundle attribute to the next maior version

If can solve the problem that the module can not find, then can solve a lot of problems of finding the path.

qlaffont commented 10 months ago

So you are telling me, at this point we have no solution to use this plugin

ErKeLost commented 10 months ago

It can be solved at present, but pnpm create solid build seems to have some problems at present. I failed to build. Can you provide a warehouse that can be reproduced?

qlaffont commented 10 months ago

You have the repro here @ErKeLost : https://github.com/qlaffont/solid-start-project

ErKeLost commented 10 months ago

I tried beforeBundle false to find the picture in dist after build in your repo.

image

Did you say that the picture could not be found in dist after setting false?

image

I don't know if there's a problem with my understanding, and if it is, please tell me that I will continue to fix this problem, and I found that there is less problem of finding build products in ssr. I'll solve this problem first.

qlaffont commented 10 months ago

I have updated the example with the img tag and it doesn't work : https://github.com/qlaffont/solid-start-project/commit/4681c6cf57bd5847da8c8c8d68c571f2ea1b667a WITH beforeBundle: false :

The image is not found in dist

qlaffont commented 10 months ago

With beforeBundle: true :

[unplugin-imagemin] 📦 📦 Process start with Mode sharp
            â–¶ Not Found Image Module,  if you want to use style with image style, such as "background-image" you can use "beforeBundle: false" in plugin config
✔ Image conversion completed!

Image is found in dist but not compressed

ErKeLost commented 10 months ago

In the case of url import, you can't find the corresponding module. You can use the module import method first. I will solve this problem as soon as possible.

Thank you for your report.

qlaffont commented 10 months ago

I keep the issue until it is possible, because I need to upload image as background sometimes and I need to have these files.

qlaffont commented 10 months ago

When do you think you will work on this ? It's kind of critical for me ^^"

ErKeLost commented 10 months ago

When do you think you will work on this ? It's kind of critical for me ^^"

I have been very busy because of my work. I will solve this problem as soon as possible this week.

qlaffont commented 10 months ago

@ErKeLost any update ?

ErKeLost commented 10 months ago

@ErKeLost any update ?

I'm so sorry. I've been too busy at work lately. I don't have time to check it out.