An open API service indexing awesome lists of open source software.

https://github.com/yuan66-hub/unplugin-image-convert

Image multi format conversion plugin based on sharp
https://github.com/yuan66-hub/unplugin-image-convert

sharp unplugin vite webpack

Last synced: 5 days ago
JSON representation

Image multi format conversion plugin based on sharp

Awesome Lists containing this project

README

        

# ✨ unplugin-image-convert

## 📦 Install

```bash
npm add @yuanjianming/unplugin-image-convert -D
```

## 💪 Basic Use

- vite.config.js

```js
import { defineConfig } from 'vite'
import viteImageConvert from '@yuanjianming/unplugin-image-convert/vite'
export default defineConfig({
//....
plugins: [viteImageConvert({
test:/\.(jpe?g|png)$/,
encodeOptions:{
webp:{
// https://sharp.pixelplumbing.com/api-output#webp
},
avif:{
// https://sharp.pixelplumbing.com/api-output#avif
}
}
})],
})
```

- webpack.config.js

```js
const webpackImageConvert =require('@yuanjianming/unplugin-image-convert/webpack')

module.exports ={
plugins:[
webpackImageConvert({
test:/\.(jpe?g|png)$/,
encodeOptions:{
webp:{
// https://sharp.pixelplumbing.com/api-output#webp
},
avif:{
// https://sharp.pixelplumbing.com/api-output#avif
}
}
})
]
}

```

## 👨‍💻 Config

| option | type | default | describe |
| ---- | ---- | ---- | ---- |
| `test` | `RegExp` | '' | Regular expression for image resource file path
| `encodeOptions` | `SharpOutputOption` | `webp:{},avif:{}` | Support format conversion for `jpeg`, `png`, `webp`, `avif`, `heif`, `jxl`, `gif`, `Jp2`, and `tif`

## 💪 Default Config

```js
{
test:/\.(jpe?g|png)$/,
encodeOptions:{
webp:{
// https://sharp.pixelplumbing.com/api-output#webp
},
avif:{
// https://sharp.pixelplumbing.com/api-output#avif
}
}
}
```