# rollup-plugin-napi-image

> Rollup plugin for optimizing images powered by @napi-rs/image

Latest version **0.6.1** (published 2023-04-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install rollup-plugin-napi-image
pnpm add rollup-plugin-napi-image
yarn add rollup-plugin-napi-image
bun add rollup-plugin-napi-image
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.1 |
| Published | 2023-04-25 |
| First published | 2022-12-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | nemurubaka |
| Maintainers | nemurubaka |
| Keywords | image, rollup-plugin, rollup, vite, vite-compatible, compression, lossless, jpg, jpeg |

## Links

- npm: https://www.npmjs.com/package/rollup-plugin-napi-image
- Repository: https://github.com/cijiugechu/rollup-plugin-napi-image
- Homepage: https://github.com/cijiugechu/rollup-plugin-napi-image#readme
- Issues: https://github.com/cijiugechu/rollup-plugin-napi-image/issues
- npm.io page: https://npm.io/package/rollup-plugin-napi-image

## Dependencies (2)

- [@napi-rs/image](https://npm.io/package/@napi-rs/image.md) ^1.6.1
- [@rollup/pluginutils](https://npm.io/package/@rollup/pluginutils.md) ^5.0.2

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.6.1 (latest) — 2023-04-25
- 0.6.0 — 2023-04-22
- 0.5.1 — 2023-03-13
- 0.5.0 — 2023-03-11
- 0.4.6 — 2023-03-01
- 0.4.5 — 2023-02-11
- 0.4.4 — 2023-01-29
- 0.4.3 — 2023-01-06
- 0.4.2 — 2023-01-06
- 0.4.1 — 2023-01-04
- 0.4.0 — 2023-01-03
- 0.3.1 — 2023-01-02
- 0.3.0 — 2023-01-01
- 0.2.0 — 2022-12-31
- 0.1.0 — 2022-12-31

## README

# rollup-plugin-napi-image

Rollup plugin for optimizing images powered by [@napi-rs/image](https://github.com/Brooooooklyn/Image), without involving `node-gyp`.

see [example](../playground/)

## Usage

### 1. install

```shell
npm install rollup-plugin-napi-image --save-dev
# or you use pnpm
pnpm add  rollup-plugin-napi-image -D
```

### 2. add plugin to your config file

- if you are using `rollup`, import this plugin and add to `plugins` field like following:

```typescript
import { defineConfig } from 'rollup'
import { napiImage } from 'rollup-plugin-napi-image'
// ... other lines

export default defineConfig({
  plugins: [
    /* other plugins */
    napiImage({
      mode: 'lossy',
      quality: 75,
    }),
  ],
})
```

- if you are using `vite` , just replace the first line of above with `import { defineConfig } from 'vite'`

### 3. options

| name      | type                                          | default | description                                                                                                                                                   |
| :-------- | :-------------------------------------------- | :------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `include` | `RegExp \| string \| Array<string \| RegExp>` | null    | A picomatch pattern, or array of patterns, which specifies the files in the build the plugin should operate on. By default all supported images are targeted. |
| `exclude` | `RegExp \| string \| Array<string \| RegExp>` | null    | A picomatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. By default no images are ignored.                 |
| `mode`    | `'lossy' \| 'lossless'`                       |         | The optimization mode applied to images, when `mode` is `lossy` , you can specify `quality` for the process.                                                  |
| `quality` | `number`                                      | 75      | Only works when `mode` is `lossy`.                                                                                                                            |
| `toModernExt` | `(ext: SupportedExt) => ModernExt` | `ext => ext` | A conversion function that converts the specified image format to a modern image format. |

### 4. supported formats

1. `jpg/jpeg`
2. `png`
3. `webp`
4. `avif`

## License

MIT &copy; [nemurubaka](https://github.com/cijiugechu)

---
_Source: https://npm.io/package/rollup-plugin-napi-image · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
