rollup-plugin-jpg-progressive v1.0.0
Rollup Plugin JPG Progressive
Rollup 渐进式 JPG 插件
一个将基线 JPG 图像转换为渐进式 JPG 图像的 Rollup 插件。 A Rollup plugin that converts baseline JPG images to progressive JPG images.
安装
Installation
npm install rollup-plugin-jpg-progressive
使用
Usage
在你的 Rollup 配置文件中引入并使用插件: Import and use the plugin in your Rollup configuration file:
import jpgProgressivePlugin from 'rollup-plugin-jpg-progressive';
export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'cjs'
},
plugins: [
jpgProgressivePlugin({
quality: 80, // 图片质量 (1-100),默认 80 | Image quality (1-100), default 80
mozjpeg: false // 是否使用 mozjpeg 压缩,默认 false | Use mozjpeg compression, default false
})
]
};
配置选项
Configuration Options
quality
(Number): 图片质量,范围 1 到 100,默认值为 80。 | Image quality, range 1 to 100, default 80.mozjpeg
(Boolean): 是否使用 mozjpeg 压缩,默认值为 false。 | Use mozjpeg compression, default false.
工作原理
How It Works
该插件会自动检测并处理项目中的 .jpg
和 .jpeg
文件,使用 sharp 库将其转换为渐进式 JPG 图像。渐进式 JPG 图像在加载时会先显示低分辨率的图像,然后逐渐提高分辨率,从而改善用户体验。
The plugin automatically detects and processes .jpg
and .jpeg
files in your project, using the sharp library to convert them to progressive JPG images. Progressive JPG images display a low-resolution version first, then gradually increase in resolution, improving user experience.
示例
Example
假设你有一个 image.jpg
文件,使用该插件后,输出的图像将自动转换为渐进式 JPG。
If you have an image.jpg
file, after using this plugin, the output image will be automatically converted to a progressive JPG.
注意事项
Notes
6 months ago