nuxt / image

Plug-and-play image optimization for Nuxt applications.
https://image.nuxt.com
MIT License
1.32k stars 267 forks source link

Option to deactivate image generation for static sites #761

Open thomas4Bitcraft opened 1 year ago

thomas4Bitcraft commented 1 year ago

It would be good to opt-in the image-generation for the module. For big websites, the generation of the images takes a very long time and will require a very big data transfer. The path should stay the same (_ipx/..) and has to be handled via Cloudfront or similar services

Smef commented 1 year ago

Wouldn't this fail if you are using IPX as your provider? The images wouldn't be generated and would never exist. All of your links would point to nothing, since the _ipx directory and all the contents would't exist.

If you're using images hosted somewhere else you'd probably want to generate them there and then src them as normal, or set up a new custom Nuxt Image provider for the place where you're sourcing your images from.

thomas4Bitcraft commented 1 year ago

No, because it's routed via Cloudfront. We implemented this by now and it works like this:

Smef commented 1 year ago

This sounds like custom provider territory to me, but maybe others can comment as well.

If I was going to implement something like this myself I'd do it by having my default provider configured by the .env file, which would be read by the nuxt image configuration in nuxt.config. In dev it would use the default IPX provider, and in production it would be my "lambdaIPX" provider or whatever which would hit your Cloudfront assets URLs and wouldn't do the image processing during generate.

Sadarex commented 1 year ago

How about an opt-out option instead of opt-in? This way we could generate everything else fast. Especially for CICD Pipelines the process of always rendering every image is very time consuming and requires long upload times.

My photography website I work on generates about 1,6GB of image files (3 formats and 5 sizes each).

Smef commented 1 year ago

I think the "opt out" you're looking for exists already, which would be to change your provider. The IPX provider means "please generate the images." Any other provider won't generate images through IPX, including the "none" provider. You can even make your own provider which just points to your directory of existing images. You can manage all this through your nuxt.config.ts file. As long as you're not using IPX as your provider and therefore explicitly asking for the images to be generated, your build process won't generate the images.

Smef commented 1 year ago

Also, I understand the slow generating with images for SSG. We have a site with about 2k images from a CMS which need to be generated which runs through SSG and gets deployed on Cloudflare Pages. It was just taking too long to do a full deploy with NuxtImage generating the images on each deploy.

Our solution was to generate the images once, ahead of time, and store them in S3. Then on deploy we don't do the image generation, and instead just reference the pre-generated images in the S3 bucket through a different provider. This skips the image generation during the SSG generate process on Cloudflare.

Sadarex commented 1 year ago

@Smef Thanks for your input. This would be my workaround until another solution is there.

But what I meant and want is an option where we don't have to change the code everytime we want to generate with or without the image pre-rendering.

Something with a cli option or another build script.

Smef commented 1 year ago

You don't need to change any code to do this. This would be set up through your provider configuration in nuxt.config.ts file, which should read the provider setting from your environment. You main build process would use something other than IPX, and your image build process would use IPX.

Smef commented 1 year ago

Also, if you don't event want to set it in the .env, you could instead set it on the CLI before you run your build commands or as part of your npm script call itself, which would let you do a different value each time if you wanted. This matches your "cli or another build script" request too!