β οΈ IMPORTANT: This module is under maintenance mode, that means that new features are not developed but bug fixes are adressed.βΉοΈ NOTE: For Nuxt v3, it's recommended the Official Nuxt Image Module https://github.com/nuxt/image
π π Nuxt Optimized Images
Automatically optimizes images used in Nuxt.js projects (JPEG, PNG, SVG, WebP and GIF).
This module is inspired by the work of Cyril Wanner in next-optimized-images.
Read this in other languages: English, EspaΓ±ol
Features
Image sizes can often get reduced up to 60%, but this is not the only thing @aceforth/nuxt-optimized-images
does:
- Reduces image size by optimizing images during build.
- Improves loading speed by providing progressive images (for formats that support it).
- JPEG/PNG images can be converted to
WebP
on the fly for an even smaller size. - Can resize images or generate low-quality image placeholders (lqip) and extract the dominant colors of it.
- Provides query params for file-specific handling/settings.
- And supports these features already included in Nuxt.js:
- Content hash to the file name so images can get cached on CDN level and in the browser for a long time.
- Inlined small images to save HTTP requests and additional roundtrips.
- Same URLs for unchanged images over multiple builds for long time caching.
Installation
node >= 10
and nuxt >= 2
are required.
npm install --save-dev @aceforth/nuxt-optimized-images
or
yarn add --dev @aceforth/nuxt-optimized-images
Add @aceforth/nuxt-optimized-images
to buildModules
section of nuxt.config.js:
< 2.9.0
, use modules
instead.
{
buildModules: [
'@aceforth/nuxt-optimized-images',
],
optimizedImages: {
optimizeImages: true
}
}
See the configuration section for all available options.
Optimization Packages
You have to install the optimization packages you need in your project in addition to this module. Then, @aceforth/nuxt-optimized-images
detects all the supported packages and uses them.
So you only have to install these packages with npm, there is no additional step needed after that.
The following optimization packages are available and supported:
Optimization Package | Description | Project Link |
---|---|---|
imagemin-mozjpeg |
Optimizes JPEG images | Link |
imagemin-pngquant |
Optimizes PNG images | Link |
imagemin-optipng |
Alternative for optimizing PNG images | Link |
imagemin-gifsicle |
Optimizes GIF images | Link |
imagemin-svgo |
Optimizes SVG images and icons | Link |
webp-loader |
Optimizes WebP images and can convert JPEG/PNG images to WebP on the fly (WebP resource query) | Link |
lqip-loader |
Generates low quality image placeholders and can extract the dominant colors of an image (lqip resource query) | Link |
responsive-loader |
Can resize images on the fly and create multiple versions of it for a srcSet . Important: You need to additionally install either jimp (node implementation, slower) or sharp (binary, faster) |
Link |
sqip-loader |
Loads images and exports tiny SQIP previews as image/svg+xml URL-encoded data |
Link |
Example: If you have JPG, PNG, and SVG images in your project, you would then need to run
npm install --save-dev imagemin-mozjpeg imagemin-pngquant imagemin-svgo
# or
yarn add --dev imagemin-mozjpeg imagemin-pngquant imagemin-svgo
To install all optional packages, run:
npm install --save-dev imagemin-mozjpeg imagemin-pngquant imagemin-gifsicle imagemin-svgo webp-loader lqip-loader responsive-loader sqip-loader sharp
# or
yarn add --dev imagemin-mozjpeg imagemin-pngquant imagemin-gifsicle imagemin-svgo webp-loader lqip-loader responsive-loader sqip-loader sharp
optimizeImagesInDev
config.
Documentation & Support
π If you want extra details of how to configure and use this project, the full documentation is available at https://marquez.co/docs/nuxt-optimized-images/.- π For Bug reports or Feature requests, use the Issues section.
- π¬ For questions, you can also use the Discussions section.
π You may also want to follow me on Twitter.
Professional Support
This project is sponsored by me, a Full Stack Developers. If you require Professional Assistance on your project(s), please contact me at https://marquez.co.
Code of Conduct
Everyone participating in this project is expected to agree to abide by the Code of Conduct.
License
Code released under the MIT License.