{"id":13456504,"url":"https://github.com/cyrilwanner/next-optimized-images","last_synced_at":"2025-05-14T10:07:55.779Z","repository":{"id":39008284,"uuid":"123820628","full_name":"cyrilwanner/next-optimized-images","owner":"cyrilwanner","description":"🌅 next-optimized-images automatically optimizes images used in next.js projects (jpeg, png, svg, webp and gif).","archived":false,"fork":false,"pushed_at":"2023-01-04T23:37:36.000Z","size":8087,"stargazers_count":2229,"open_issues_count":134,"forks_count":91,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-04-03T18:11:12.373Z","etag":null,"topics":["image","nextjs","optimization","plugin","react"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cyrilwanner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-04T19:19:54.000Z","updated_at":"2025-03-31T01:05:06.000Z","dependencies_parsed_at":"2023-02-03T00:15:45.812Z","dependency_job_id":null,"html_url":"https://github.com/cyrilwanner/next-optimized-images","commit_stats":null,"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrilwanner%2Fnext-optimized-images","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrilwanner%2Fnext-optimized-images/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrilwanner%2Fnext-optimized-images/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrilwanner%2Fnext-optimized-images/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cyrilwanner","download_url":"https://codeload.github.com/cyrilwanner/next-optimized-images/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248336168,"owners_count":21086729,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["image","nextjs","optimization","plugin","react"],"created_at":"2024-07-31T08:01:23.192Z","updated_at":"2025-04-11T03:33:41.046Z","avatar_url":"https://github.com/cyrilwanner.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Nextjs Plugins"],"sub_categories":[],"readme":"# :sunrise: next-optimized-images [![npm version](https://badgen.net/npm/v/next-optimized-images)](https://www.npmjs.com/package/next-optimized-images) [![license](https://badgen.net/github/license/cyrilwanner/next-optimized-images)](https://github.com/cyrilwanner/next-optimized-images/blob/master/LICENSE) [![downloads](https://badgen.net/npm/dt/next-optimized-images)](https://www.npmjs.com/package/next-optimized-images)\n\n**:bulb: Version 3 is coming!**\nIt introduces a complete rewrite with many new features and bugfixes. If you want to help developing and testing the upcoming major version, please check out the [canary branch](https://github.com/cyrilwanner/next-optimized-images/tree/canary) for installation instructions and more information about the new features. ([RFC issue](https://github.com/cyrilwanner/next-optimized-images/issues/120))\n\n---\n\nAutomatically optimize images used in [next.js](https://github.com/zeit/next.js) projects (`jpeg`, `png`, `svg`, `webp` and `gif`).\n\nImage sizes can often get reduced between 20-60%, but this is not the only thing `next-optimized-images` does:\n\n* **Reduces image size** by optimizing images during build\n* Improves loading speed by providing **progressive images** (for formats that support it)\n* **Inlines small images** to save HTTP requests and additional roundtrips\n* Adds a content hash to the file name so images can get cached on CDN level and in the browser for a long time\n* Same image URLs over multiple builds for long time caching\n* Provides **[query params](#query-params)** for file-specific handling/settings\n* jpeg/png images can be **converted to [`webp` on the fly](#webp)** for an even smaller size\n* Provides the possibility to use **[`SVG sprites`](#sprite)** for a better performance when using the same icons multiple times (e.g. in a list)\n* Can **[resize](#resize)** images or generate different **placeholders while lazy loading** images: [low quality images](#lqip), [dominant colors](#lqip-colors) or [image outlines](#trace)\n\n## Table of contents\n\n- [Installation](#installation)\n- [Optimization Packages](#optimization-packages)\n- [Usage](#usage)\n  - [Query Params](#query-params)\n- [Configuration](#configuration)\n- [Example](#example)\n- [See also](#see-also)\n- [License](#license)\n\n## Installation\n\n```\nnpm install next-optimized-images\n```\n\n*Node \u003e= 8 is required for version 2. If you need to support older node versions, you can still use [version 1](https://github.com/cyrilwanner/next-optimized-images/tree/v1#readme) of next-optimized-images.*\n\nEnable the plugin in your Next.js configuration file:\n\n```javascript\n// next.config.js\nconst withPlugins = require('next-compose-plugins');\nconst optimizedImages = require('next-optimized-images');\n\nmodule.exports = withPlugins([\n  [optimizedImages, {\n    /* config for next-optimized-images */\n  }],\n\n  // your other plugins here\n\n]);\n```\n\nSee the [configuration](#configuration) section for all available options.\n\n:warning: **From version 2 on, images won't get optimized out of the box anymore. You have to install the optimization packages you really need in addition to this plugin.**\nThis doesn't force you to download big optimization libraries you don't even use.\nPlease check out the table of all [optional optimization packages](#optimization-packages).\n\nThe example above uses [next-compose-plugins](https://github.com/cyrilwanner/next-compose-plugins) for a cleaner API when using many plugins, see its readme for a more detailed example. `next-optimized-images` also works with the standard plugin api:\n\n```javascript\n// next.config.js\nconst withOptimizedImages = require('next-optimized-images');\n\nmodule.exports = withOptimizedImages({\n  /* config for next-optimized-images */\n\n  // your config for other plugins or the general next.js here...\n});\n```\n\n## Optimization Packages\n\nStarting from version 2, you have to install the optimization packages you need in your project in addition to this plugin. `next-optimized-images` then detects all the supported packages and uses them.\n\n**So you only have to install these packages with npm, there is no additional step needed after that.**\n\nThe following optimization packages are available and supported:\n\n| Optimization Package | Description | Project Link |\n| -------------------- | ----------- | ------------ |\n| `imagemin-mozjpeg`   | Optimizes JPEG images. | [Link](https://www.npmjs.com/package/imagemin-mozjpeg)\n| `imagemin-optipng`   | Optimizes PNG images. | [Link](https://www.npmjs.com/package/imagemin-optipng)\n| `imagemin-pngquant`  | Alternative for optimizing PNG images. | [Link](https://www.npmjs.com/package/imagemin-pngquant)\n| `imagemin-gifsicle`  | Optimizes GIF images. | [Link](https://www.npmjs.com/package/imagemin-gifsicle)\n| `imagemin-svgo`      | Optimizes SVG images and icons. | [Link](https://www.npmjs.com/package/imagemin-svgo)\n| `svg-sprite-loader`  | Adds the possibility to use svg sprites for a better performance. Read the [sprite](#sprite) section for more information. | [Link](https://www.npmjs.com/package/svg-sprite-loader)\n| `webp-loader`        | Optimizes WebP images and can convert JPEG/PNG images to WebP on the fly ([webp resource query](#webp)). | [Link](https://www.npmjs.com/package/webp-loader)\n| `lqip-loader`        | Generates low quality image placeholders and can extract the dominant colors of an image ([lqip resource query](#lqip)) | [Link](https://www.npmjs.com/package/lqip-loader)\n| `responsive-loader`  | Can resize images on the fly and create multiple versions of it for a `srcset`.\u003cbr\u003e**Important**: You need to additionally install either `jimp` (node implementation, slower) or `sharp` (binary, faster) | [Link](https://www.npmjs.com/package/responsive-loader)\n| `image-trace-loader` | Generates SVG image [outlines](https://twitter.com/mikaelainalem/status/918213244954861569) which can be used as a placeholder while loading the original image ([trace resource query](#trace)). | [Link](https://www.npmjs.com/package/image-trace-loader)\n\n\u003e Example: If you have JPG, PNG, and SVG images in your project, you would then need to run\n\u003e ```bash\n\u003e npm install imagemin-mozjpeg imagemin-optipng imagemin-svgo\n\u003e ```\n\nTo install *all* optional packages, run:\n```bash\nnpm install imagemin-mozjpeg imagemin-optipng imagemin-gifsicle imagemin-svgo svg-sprite-loader webp-loader lqip-loader responsive-loader jimp image-trace-loader\n```\n\n:warning: Please note that by default, images are only optimized for **production builds, not development builds**. However, this can get changed with the [`optimizeImagesInDev` config](#optimizeimagesindev).\n\n:bulb: Depending on your build/deployment setup, it is also possibile to install these as devDependencies. Just make sure that the packages are available when you build your project.\n\n:information_source: Since version 2.5, `ico` files are also optionally supported but need to be enabled in the [`handleImages` config](#handleimages).\n\n## Usage\n\nYou can now import or require your images directly in your react components:\n\n```javascript\nimport React from 'react';\n\nexport default () =\u003e (\n  \u003cdiv\u003e\n    \u003cimg src={require('./images/my-image.jpg')} /\u003e\n    \u003cimg src={require('./images/my-small-image.png')} /\u003e\n    \u003cimg src={require('./images/my-icon.svg')} /\u003e\n  \u003c/div\u003e\n);\n\n/**\n * Results in:\n *\n * \u003cdiv\u003e\n *   \u003cimg src=\"/_next/static/images/my-image-5216de428a8e8bd01a4aa3673d2d1391.jpg\" /\u003e\n *   \u003cimg src=\"data:image/png;base64,...\" /\u003e\n *   \u003cimg src=\"/_next/static/images/my-icon-572812a2b04ed76f93f05bf57563c35d.svg\" /\u003e\n * \u003c/div\u003e\n */\n```\n\nPlease be aware that images only get optimized [in production by default](#optimizeimagesindev) to reduce the build time in your development environment.\n\nIf you are using CSS modules, this package also detects images and optimized them in `url()` values in your css/sass/less files:\n\n```scss\n.Header {\n  background-image: url('./images/my-image.jpg');\n}\n\n/**\n * Results in:\n *\n * .Header {\n *   background-image: url('/_next/static/images/my-image-5216de428a8e8bd01a4aa3673d2d1391.jpg');\n * }\n */\n```\n\nIf the file is below the [limit for inlining images](#inlineimagelimit), the `require(...)` will return a base64 data-uri (`data:image/jpeg;base64,...`).\n\nOtherwise, `next-optimized-images` will copy your image into the static folder of next.js and the `require(...)` returns the path to your image in this case (`/_next/static/images/my-image-5216de428a8e8bd01a4aa3673d2d1391.jpg`).\n\nYou can use both variants directly on an image in the `src` attribute or in your CSS file inside an `url()` value.\n\n### Query params\n\n\u003e *If you are using flow or eslint-plugin-import and are experiencing some issues with query params, check out the [solution posted by @eleith](https://github.com/cyrilwanner/next-optimized-images/issues/23).*\n\nThere are some cases where you don't want to reference a file or get a base64 data-uri but you actually want to include the raw file directly into your HTML.\nEspecially for SVGs because you can't style them with CSS if they are in an `src` attribute on an image.\n\nSo there are additional options you can specify as query params when you import the images.\n\n* [`?include`](#include): Include the raw file directly (useful for SVG icons)\n* [`?webp`](#webp): Convert a JPEG/PNG image to WebP on the fly\n* [`?inline`](#inline): Force inlining an image (data-uri)\n* [`?url`](#url): Force an URL for a small image (instead of data-uri)\n* [`?original`](#original): Use the original image and do not optimize it\n* [`?lqip`](#lqip): Generate a low quality image placeholder\n* [`?lqip-colors`](#lqip-colors): Extract the dominant colors of an image\n* [`?trace`](#trace): Use traced outlines as loading placeholder\n* [`?resize`](#resize): Resize an image\n* [`?sprite`](#sprite): Use SVG sprites\n\n#### ?include\n\nThe image will now directly be included in your HTML without a data-uri or a reference to your file.\n\nAs described above, this is useful for SVGs so you can style them with CSS.\n\n```javascript\nimport React from 'react';\n\nexport default () =\u003e (\n  \u003cdiv dangerouslySetInnerHTML={{__html: require('./images/my-icon.svg?include')}} /\u003e\n);\n\n/**\n * Results in:\n *\n * \u003cdiv\u003e\n *   \u003csvg width=\"16\" height=\"16\" xmlns=\"http://www.w3.org/2000/svg\"\u003e\n *     \u003cpath d=\"M8 0C3.589 0 0 3.589 0 8s3.589 ...\" style=\"filled-opacity:1\" fill-rule=\"evenodd\"\u003e\n *     \u003c/path\u003e\n *   \u003c/svg\u003e\n * \u003c/div\u003e\n */\n```\n\nThe image will still get optimized, even if it is directly included in your content (but by [default only in production](#optimizeimagesindev)).\n\n#### ?webp\n\n\u003e Requires the optional optimization package `webp-loader` (`npm install webp-loader`)\n\nWebP is an even better and smaller image format but it is still not that common yet and developers often only receive jpeg/png images.\n\nIf this `?webp` query parameter is specified, `next-optimized-images` automatically converts a JPEG/PNG image to the new WebP format.\n\nFor browsers that don't yet support WebP, you can also provide a fallback using the `\u003cpicture\u003e` tag:\n\n```javascript\nimport React from 'react';\n\nexport default () =\u003e (\n  \u003cpicture\u003e\n    \u003csource srcSet={require('./images/my-image.jpg?webp')} type=\"image/webp\" /\u003e\n    \u003csource srcSet={require('./images/my-image.jpg')} type=\"image/jpeg\" /\u003e\n    \u003cimg src={require('./images/my-image.jpg')} /\u003e\n  \u003c/picture\u003e\n);\n\n/**\n * Results in:\n * \u003cpicture\u003e\n *   \u003csource srcset=\"/_next/static/images/my-image-d6816ecc28862cf6f725b29b1d6aab5e.jpg.webp\" type=\"image/webp\" /\u003e\n *   \u003csource srcset=\"/_next/static/images/my-image-5216de428a8e8bd01a4aa3673d2d1391.jpg\" type=\"image/jpeg\" /\u003e\n *   \u003cimg src=\"/_next/static/images/my-image-5216de428a8e8bd01a4aa3673d2d1391.jpg\" /\u003e\n * \u003c/picture\u003e\n */\n```\n\n#### ?inline\n\nYou can specify a [limit for inlining](#inlineimagelimit) images which will include it as a data-uri directly in your content instead of referencing a file if the file size is below that limit.\n\nYou usually don't want to specify a too high limit but there may be cases where you still want to inline larger images.\n\nIn this case, you don't have to set the global limit to a higher value but you can add an exception for a single image using the `?inline` query options.\n\n```javascript\nimport React from 'react';\n\nexport default () =\u003e (\n  \u003cimg src={require('./images/my-image.jpg?inline')} /\u003e\n);\n\n/**\n * Results in:\n *\n * \u003cimg src=\"data:image/png;base64,...\" /\u003e\n *\n * Even if the image size is above the defined limit.\n */\n```\n\nThe inlining will only get applied to exactly this import, so if you import the image a second time without the `?inline` option, it will then get normally referenced as a file if it is above your limit.\n\n#### ?url\n\nWhen you have an image smaller than your defined [limit for inlining](#inlineimagelimit), it normally gets inlined automatically.\nIf you don't want a specific small file to get inlined, you can use the `?url` query param to always get back an image URL, regardless of the inline limit.\n\nIf you are using this option a lot, it could also make sense to [disable the inlining](#inlineimagelimit) completely and use the [`?inline`](#inline) param for single files.\n\n```javascript\nimport React from 'react';\n\nexport default () =\u003e (\n  \u003cimg src={require('./images/my-image.jpg?url')} /\u003e\n);\n\n/**\n * Results in:\n *\n * \u003cimg src=\"/_next/static/images/my-image-5216de428a8e8bd01a4aa3673d2d1391.jpg\" /\u003e\n *\n * Even if the image size is below the defined inlining limit.\n */\n```\n\nThe inlining will only get disabled for exactly this import, so if you import the image a second time without the `?url` option, it will then get inlined again if it is below your limit.\n\n#### ?original\n\nThe image won't get optimized and used as it is.\nIt makes sense to use this query param if you know an image already got optimized (e.g. during export) so it doesn't get optimized again a second time.\n\n```javascript\nimport React from 'react';\n\nexport default () =\u003e (\n  \u003cimg src={require('./images/my-image.jpg?original')} /\u003e\n);\n```\n\nThis can also be combined with the `?url` or `?inline` resource query (e.g. `?original\u0026inline`).\n\n#### ?lqip\n\n\u003e Requires the optional package `lqip-loader` (`npm install lqip-loader`)\n\nWhen using this resource query, a very small (about 10x7 pixel) image gets created.\nYou can then display this image as a placeholder until the real (big) image has loaded.\n\nYou will normally stretch this tiny image to the same size as the real image is, like *medium.com* does.\nTo make the stretched image look better in chrome, check out [this solution](https://github.com/zouhir/lqip-loader/issues/5) and add a blur filter to your image.\n\n```javascript\nimport React from 'react';\n\nexport default () =\u003e (\n  \u003cimg src={require('./images/my-image.jpg?lqip')} /\u003e\n);\n\n/**\n * Replaces the src with a tiny image in base64.\n */\n```\n\n#### ?lqip-colors\n\n\u003e Requires the optional package `lqip-loader` (`npm install lqip-loader`)\n\nThis resource query returns you an **array with hex values** of the dominant colors of an image.\nYou can also use this as a placeholder until the real image has loaded (e.g. as a background) like the *Google Picture Search* does.\n\nThe number of colors returned can vary and depends on how many different colors your image has.\n\n```javascript\nimport React from 'react';\n\nexport default () =\u003e (\n  \u003cdiv style={{ backgroundColor: require('./images/my-image.jpg?lqip-colors')[0] }}\u003e...\u003c/div\u003e\n);\n\n/**\n * require('./images/my-image.jpg?lqip-colors')\n *\n * returns for example\n *\n * ['#0e648d', '#5f94b5', '#a7bbcb', '#223240', '#a4c3dc', '#1b6c9c']\n */\n```\n\n#### ?trace\n\n\u003e Requires the optional package `image-trace-loader` (`npm install image-trace-loader`)\n\nWith the `?trace` resource query, you can generate [SVG image outlines](https://twitter.com/mikaelainalem/status/918213244954861569) which can be used as a placeholder while loading the original image.\n\n```javascript\nimport React from 'react';\nimport MyImage from './images/my-image.jpg?trace';\n\nexport default () =\u003e (\n  \u003cdiv\u003e\n    \u003cimg src={MyImage.trace} /\u003e   {/* \u003c-- SVG trace */}\n    \u003cimg src={MyImage.src} /\u003e     {/* \u003c-- Normal image which you want to lazy load */}\n  \u003c/div\u003e\n);\n\n/**\n * Results in:\n *\n * \u003cdiv\u003e\n *  \u003cimg src=\"data:image/svg+xml,...\"\u003e\n *  \u003cimg src=\"/_next/static/images/image-trace-85bf5c58ce3d91fbbf54aa03c44ab747.jpg\"\u003e\n * \u003c/div\u003e\n */\n```\n\n`require('./images/my-image.jpg?trace')` returns an object containing the trace (`trace`) as an inlined SVG and the normal image (`src`) which also gets optimized.\n\nThe trace will have exactly the same width and height as your normal image.\n\nOptions for the loader can be set in the [plugin configuration](#imagetrace).\n\n#### ?resize\n\n\u003e Requires the optional package `responsive-loader` (`npm install responsive-loader`)\n\u003e and either `jimp` (node implementation, slower) or `sharp` (binary, faster)\n\nAfter the `?resize` resource query, you can add any other query of the [`responsive-loader`](https://www.npmjs.com/package/responsive-loader) which allows you to resize images and create whole source sets.\n\n```javascript\nimport React from 'react';\n\nconst oneSize = require('./images/my-image.jpg?resize\u0026size=300');\nconst multipleSizes = require('./images/my-image.jpg?resize\u0026sizes[]=300\u0026sizes[]=600\u0026sizes[]=1000');\n\nexport default () =\u003e (\n  \u003cdiv\u003e\n    {/* Single image: */}\n    \u003cimg src={oneSize.src} /\u003e\n\n    {/* Source set with multiple sizes: */}\n    \u003cimg srcSet={multipleSizes.srcSet} src={multipleSizes.src} /\u003e\n  \u003c/div\u003e\n);\n```\n\nIf only the `size` or `sizes` param is used, the `?resize` param can also be omitted (e.g. `my-image.jpg?size=300`). But it is required for all other parameters of `responsive-loader`.\n\nYou can also set global configs in the [`responsive`](#responsive) property (in the `next.config.js` file) and define, for example, default sizes which will get generated when you don't specify one for an image (e.g. only `my-image.jpg?resize`).\n\n#### ?sprite\n\n\u003e Requires the optional optimization packages `imagemin-svgo` and `svg-sprite-loader` (`npm install imagemin-svgo svg-sprite-loader`)\n\nIf you need to style or animate your SVGs [?include](#?include) might be the wrong option, because that ends up in a lot of DOM elements, especially when using the SVG in list-items etc.\nIn that case, you can use `?sprite` which uses [svg-sprite-loader](https://github.com/kisenka/svg-sprite-loader) to render and inject an SVG sprite in the page automatically.\n\n```javascript\nimport React from 'react';\nimport MyIcon from './icons/my-icon.svg?sprite';\n\nexport default () =\u003e (\n  \u003cdiv\u003e\n    my page..\n    \u003cMyIcon /\u003e\n  \u003c/div\u003e\n);\n```\n\nAll props passed to the imported sprite will get applied to the `\u003csvg\u003e` element, so you can add a class normally with `\u003cMyIcon className=\"icon-class\" /\u003e`.\n\nThe `svg-sprite-loader` object also gets exposed if you want to build your own component:\n\n```javascript\nimport React from 'react';\nimport icon from './icons/icon.svg?sprite';\n\nexport default () =\u003e (\n  \u003cdiv\u003e\n    my page..\n    \u003csvg viewBox={icon.viewBox}\u003e\n      \u003cuse xlinkHref={`#${icon.id}`} /\u003e\n    \u003c/svg\u003e\n  \u003c/div\u003e\n);\n```\n\nTo also make this work for server-side rendering, you need to add these changes to your `_document.jsx` file (read [here](https://nextjs.org/docs/#custom-document) if you don't have this file yet):\n\n```javascript\n// ./pages/_document.js\nimport Document, { Head, Main, NextScript } from 'next/document';\nimport sprite from 'svg-sprite-loader/runtime/sprite.build';\n\nexport default class MyDocument extends Document {\n  static async getInitialProps(ctx) {\n    const initialProps = await Document.getInitialProps(ctx);\n    const spriteContent = sprite.stringify();\n\n    return {\n      spriteContent,\n      ...initialProps,\n    };\n  }\n\n  render() {\n    return (\n      \u003chtml\u003e\n        \u003cHead\u003e{/* your head if needed */}\u003c/Head\u003e\n        \u003cbody\u003e\n          \u003cdiv dangerouslySetInnerHTML={{ __html: this.props.spriteContent }} /\u003e\n          \u003cMain /\u003e\n          \u003cNextScript /\u003e\n        \u003c/body\u003e\n      \u003c/html\u003e\n    );\n  }\n}\n```\n\n## Configuration\n\nThis plugin uses [img-loader](https://www.npmjs.com/package/img-loader) under the hood which is based on [mozjpeg](https://github.com/imagemin/imagemin-mozjpeg), [optipng](https://github.com/imagemin/imagemin-optipng), [gifsicle](https://github.com/imagemin/imagemin-gifsicle) and [svgo](https://github.com/imagemin/imagemin-svgo).\n\nThe default options for these optimizers should be enough in most cases, but you can overwrite every available option if you want to.\n\n#### handleImages\n\nType: `string[]`\u003cbr\u003e\nDefault: `['jpeg', 'png', 'svg', 'webp', 'gif']`\n\n`next-optimized-images` registers the webpack loader for all these file types.\nIf you don't want one of these handled by next-optimized-images because you, for example, have another plugin or custom loader rule, simply remove it from the array.\n\nPlease note that an image being handled does not mean it also gets automatically optimized. The required optimization package for that image also has to be installed. Please read the [optimization packages](#optimization-packages) section for more information.\n\nIf an image gets handled but not optimized, it means that the original image will get used and copied for the build.\n\n:information_source: Since version 2.5, `ico` files are also supported but for backwards compatibility, they need to be manually enabled.\nBy adding `'ico'` to the `handleImages` array, the plugin will also handle `ico` files.\n\n#### inlineImageLimit\n\nType: `number`\u003cbr\u003e\nDefault: `8192`\n\nSmaller files will get inlined with a data-uri by [url-loader](https://www.npmjs.com/package/url-loader).\nThis number defines the maximum file size (in bytes) for images to get inlined.\nIf an image is bigger, it will get copied to the static folder of next.\n\nImages will get optimized in both cases.\n\nTo completely disable image inlining, set this value to `-1`. You will then always get back an image URL.\n\n#### imagesFolder\n\nType: `string`\u003cbr\u003e\nDefault: `'images'`\n\nFolder name inside `/static/` in which the images will get copied to during build.\n\n#### imagesPublicPath\n\nType: `string`\u003cbr\u003e\nDefault: ``` `/_next/static/${imagesFolder}/` ```\n\nThe public path that should be used for image URLs. This can be used to serve\nthe optimized image from a cloud storage service like S3.\n\nFrom version 2 on, next-optimized-images uses the [`assetPrefx` config of next.js](https://nextjs.org/docs/#cdn-support-with-asset-prefix) by default, but you can overwrite it with `imagesPublicPath` specially for images.\n\n#### imagesOutputPath\n\nType: `string`\u003cbr\u003e\nDefault: ``` `static/${imagesFolder}/` ```\n\nThe output path that should be used for images. This can be used to have a custom output folder.\n\n#### imagesName\n\nType: `string`\u003cbr\u003e\nDefault: `'[name]-[hash].[ext]'`\n\nThe filename of the optimized images.\nMake sure you keep the `[hash]` part so they receive a new filename if the content changes.\n\n#### removeOriginalExtension\n\nType: `boolean`\u003cbr\u003e\nDefault: `false`\n\nWhen images converted to WebP on the fly, `.webp` was append to the filename. For example, `test.png` became `test.png.webp`. If you want to have only one filename extension like `test.webp`, you can set this option to `true`.\n\n#### optimizeImagesInDev\n\nType: `boolean`\u003cbr\u003e\nDefault: `false`\n\nFor faster development builds and HMR, images will not get optimized by default when running in development mode.\nIn production, images will always get optimized, regardless of this setting.\n\n#### mozjpeg\n\n\u003e Requires the optional optimization package `imagemin-mozjpeg` (`npm install imagemin-mozjpeg`)\n\nType: `object`\u003cbr\u003e\nDefault: `{}`\n\n[mozjpeg](https://github.com/imagemin/imagemin-mozjpeg) is used for optimizing jpeg images.\nYou can specify the options for it here.\nThe default options of `mozjpeg` are used if you omit this option.\n\n#### optipng\n\n\u003e Requires the optional optimization package `imagemin-optipng` (`npm install imagemin-optipng`)\n\nType: `object`\u003cbr\u003e\nDefault: `{}`\n\n[optipng](https://github.com/imagemin/imagemin-optipng) is used for optimizing png images by default.\nYou can specify the options for it here.\nThe default options of `optipng` are used if you omit this option.\n\n#### pngquant\n\n\u003e Requires the optional optimization package `imagemin-pngquant` (`npm install imagemin-pngquant`)\n\nType: `object`\u003cbr\u003e\nDefault: `{}`\n\n[pngquant](https://github.com/imagemin/imagemin-pngquant) is an alternative way for optimizing png images.\nThe default options of `pngquant` are used if you omit this option.\n\n#### gifsicle\n\n\u003e Requires the optional optimization package `imagemin-gifsicle` (`npm install imagemin-gifsicle`)\n\nType: `object`\u003cbr\u003e\nDefault:\n```javascript\n{\n    interlaced: true,\n    optimizationLevel: 3,\n}\n```\n\n[gifsicle](https://github.com/imagemin/imagemin-gifsicle) is used for optimizing gif images.\nYou can specify the options for it here.\nThe default options of `gifsicle` are used if you omit this option.\n\n#### svgo\n\n\u003e Requires the optional optimization package `imagemin-svgo` (`npm install imagemin-svgo`)\n\nType: `object`\u003cbr\u003e\nDefault: `{}`\n\n[svgo](https://github.com/imagemin/imagemin-svgo) is used for optimizing svg images and icons.\nYou can specify the options for it here.\nThe default options of `svgo` are used if you omit this option.\n\nSingle svgo plugins can get disabled/enabled in the plugins array:\n```javascript\n{\n  svgo: {\n    plugins: [\n      { removeComments: false }\n    ]\n  }\n}\n```\n\n#### svgSpriteLoader\n\n\u003e Requires the optional optimization packages `imagemin-svgo` and `svg-sprite-loader` (`npm install imagemin-svgo svg-sprite-loader`)\n\nType: `object`\u003cbr\u003e\nDefault:\n```javascript\n{\n  runtimeGenerator: require.resolve(path.resolve('node_modules', 'next-optimized-images', 'svg-runtime-generator.js')),\n}\n```\n\nWhen using the [svg sprite option](#sprite), [`svg-sprite-loader`](https://github.com/kisenka/svg-sprite-loader) gets used internally.\nYou can overwrite the configuration passed to this loader here.\n\n#### webp\n\n\u003e Requires the optional optimization package `webp-loader` (`npm install webp-loader`)\n\nType: `object`\u003cbr\u003e\nDefault: `{}`\n\n[imagemin-webp](https://github.com/imagemin/imagemin-webp) is used for optimizing webp images and converting other formats to webp.\nYou can specify the options for it here.\nThe default options of `imagemin-webp` are used if you omit this option.\n\n#### imageTrace\n\n\u003e Requires the optional package `image-trace-loader` (`npm install image-trace-loader`)\n\nType: `object`\u003cbr\u003e\nDefault: `{}`\n\nWhen using [`image-trace-loader`](https://github.com/EmilTholin/image-trace-loader) for the `?trace` resource query, you can define all options for the image trace loader in this object.\nThe default options of `image-trace-loader` are used if you omit this option.\n\n#### responsive\n\n\u003e Requires the optional optimization package `responsive-loader` (`npm install responsive-loader`)\n\nType: `object`\u003cbr\u003e\nDefault: `{}`\n\nThe configuration for the [`responsive-loader`](https://github.com/herrstucki/responsive-loader) can be defined here.\n\n#### defaultImageLoader\n\n\u003e Requires the optional optimization package `responsive-loader` (`npm install responsive-loader`)\n\nType: `string`\u003cbr\u003e\nDefault: `'img-loader'`\n\nBy default, img-loader handles most of the requests.\nHowever, if you use the `responsive-loader` a lot and don't want to add the [`?resize`](#resize) query param to every require, you can set this value to `'responsive-loader'`.\n\nAfter that, `responsive-loader` will handle *all* JPEG and PNG images per default, even without an additional query param.\nJust be aware that you can't use any of the query params `next-optimized-images` provides anymore on these images because the request just gets forwarded and not modified anymore.\nAll other formats (SVG, WEBP and GIF) still work as before with the `img-loader` and so have all query params available.\n\n#### optimizeImages\n\nType: `boolean`\u003cbr\u003e\nDefault: `true`\n\nIf you don't have any optimization package installed, no image will get optimized.\nIn this case, a warning gets written to the console during build to inform you about a possible misconfiguration.\nIf this config is intended and you indeed don't want the images to be optimized, you can set this value to `false` and you won't get the warning anymore.\n\n## Example\n\nThe options specified here are the **default** values.\n\nSo if they are good enough for your use-case, you don't have to specify them to have a shorter and cleaner `next.config.js` file.\n\n```javascript\n// next.config.js\nconst withPlugins = require('next-compose-plugins');\nconst optimizedImages = require('next-optimized-images');\n\nmodule.exports = withPlugins([\n  [optimizedImages, {\n    // these are the default values so you don't have to provide them if they are good enough for your use-case.\n    // but you can overwrite them here with any valid value you want.\n    inlineImageLimit: 8192,\n    imagesFolder: 'images',\n    imagesName: '[name]-[hash].[ext]',\n    handleImages: ['jpeg', 'png', 'svg', 'webp', 'gif'],\n    removeOriginalExtension: false,\n    optimizeImages: true,\n    optimizeImagesInDev: false,\n    mozjpeg: {\n      quality: 80,\n    },\n    optipng: {\n      optimizationLevel: 3,\n    },\n    pngquant: false,\n    gifsicle: {\n      interlaced: true,\n      optimizationLevel: 3,\n    },\n    svgo: {\n      // enable/disable svgo plugins here\n    },\n    webp: {\n      preset: 'default',\n      quality: 75,\n    },\n  }],\n]);\n```\n\n## See also\n\n* [next-images](https://github.com/arefaslani/next-images) if you just want images and not optimize them\n* [next-compose-plugins](https://github.com/cyrilwanner/next-compose-plugins) for a cleaner plugins API when you have many plugins in your `next.config.js` file\n* [next-plugins](https://github.com/zeit/next-plugins) for a list of official and community made plugins\n\n## License\n\n[MIT](https://github.com/cyrilwanner/next-optimized-images/blob/master/LICENSE) © Cyril Wanner\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyrilwanner%2Fnext-optimized-images","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcyrilwanner%2Fnext-optimized-images","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyrilwanner%2Fnext-optimized-images/lists"}