@aceforth/nuxt-optimized-images

中文文档
1.4.0发布于 2021/01/02MITCommonJS近 30 天下载 9721

Automatically optimizes images used in Nuxt.js projects (jpeg, png, svg, webp and gif).

原始使用文档
文档目录7 节
  1. Features
  2. Installation
  3. Optimization Packages
  4. Documentation & Support
  5. Professional Support
  6. Code of Conduct
  7. License

Codacy Badge Travis David David version License

:sunrise: :rocket: 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

:warning: 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:

:warning: If you are using Nuxt < 2.9.0, use modules instead.

{
  buildModules: [
    '@aceforth/nuxt-optimized-images',
  ],

  optimizedImages: {
    optimizeImages: true
  }
}

See the configuration section for all available options.

:warning: 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, @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 PackageDescriptionProject Link
imagemin-mozjpegOptimizes JPEG imagesLink
imagemin-pngquantOptimizes PNG imagesLink
imagemin-optipngAlternative for optimizing PNG imagesLink
imagemin-gifsicleOptimizes GIF imagesLink
imagemin-svgoOptimizes SVG images and iconsLink
webp-loaderOptimizes WebP images and can convert JPEG/PNG images to WebP on the fly (WebP resource query)Link
lqip-loaderGenerates low quality image placeholders and can extract the dominant colors of an image (lqip resource query)Link
responsive-loaderCan 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-loaderLoads images and exports tiny SQIP previews as image/svg+xml URL-encoded dataLink

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

: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.

Documentation & Support

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.

版本与发布记录

@aceforth/nuxt-optimized-images 共发布 6 个版本,首次发布于 2020/04/13;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.4.0latest2021/01/025 年前
1.3.02020/08/276 年前
1.2.02020/08/196 年前
1.1.02020/07/206 年前
1.0.12020/05/126 年前
1.0.02020/04/136 年前

关于 @aceforth/nuxt-optimized-images 的常见问题

@aceforth/nuxt-optimized-images 是什么?

Automatically optimizes images used in Nuxt.js projects (jpeg, png, svg, webp and gif).

如何安装 @aceforth/nuxt-optimized-images?

在项目目录运行 npm install @aceforth/nuxt-optimized-images,或使用 pnpm add / yarn add / bun add。

@aceforth/nuxt-optimized-images 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/aceforth__nuxt-optimized-images 是否存在。

@aceforth/nuxt-optimized-images 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@aceforth/nuxt-optimized-images 可以商用吗?

@aceforth/nuxt-optimized-images 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aceforth/nuxt-optimized-images 的下载量有多少?

根据 npm 官方下载统计,@aceforth/nuxt-optimized-images 在 2026/10/05 – 2026/11/03 这 30 天内被下载 9,721 次,日均约 324 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aceforth/nuxt-optimized-images 还在维护吗?

最新版本 1.4.0 发布于 2021/01/02(5 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/04/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。