Code Monkey home page Code Monkey logo

nuxt-optimized-images's Introduction

Bazzite Project Codacy Badge Travis David David version License

πŸŒ… πŸš€ 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 @bazzite/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 fo unchanged images over multiple builds for long time caching.

Installation

⚠️ node >= 8 and nuxt >= 2 are required.

npm install @bazzite/nuxt-optimized-images

or

yarn add @bazzite/nuxt-optimized-images

Add @bazzite/nuxt-optimized-images to modules section of nuxt.config.js:

{
  modules: [
    '@bazzite/nuxt-optimized-images',
  ],

  optimizedImages: {
    optimizeImages: true
  }
}

See the configuration section for all available options.

⚠️ Images won't get optimized out of the box. You have to install the optimization packages you really need in addition to this module. This doesn't force you to download big optimization libraries you don't even use. Please check out the table of all optional optimization packages.

Optimization Packages

You have to install the optimization packages you need in your project in addition to this module. Then, @bazzite/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 imagemin-mozjpeg imagemin-pngquant imagemin-svgo

# or

yarn add imagemin-mozjpeg imagemin-pngquant imagemin-svgo

To install all optional packages, run:

npm install imagemin-mozjpeg imagemin-pngquant imagemin-gifsicle imagemin-svgo  webp-loader lqip-loader responsive-loader sqip-loader jimp

# or

yarn add imagemin-mozjpeg imagemin-pngquant imagemin-gifsicle imagemin-svgo  webp-loader lqip-loader responsive-loader sqip-loader jimp

⚠️ Please note that by default, images are only optimized for production builds, not development builds. However, this can get changed with the optimizeImagesInDev config.

Documentation & Support

Professional Support

This project is sponsored by Bazzite. If you require Professional Assistance on your project(s), please contact us at https://www.bazzite.com/contact.

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.

nuxt-optimized-images's People

Contributors

apmatthews avatar dependabot[bot] avatar giovagnoli avatar greenkeeper[bot] avatar hecktarzuli avatar juliomrqz avatar pco2699 avatar renovate[bot] avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.