# webp-webpack-plugin

> webpack plugin of making webp format file

Latest version **1.2.6** (published 2017-12-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install webp-webpack-plugin
pnpm add webp-webpack-plugin
yarn add webp-webpack-plugin
bun add webp-webpack-plugin
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.6 |
| Published | 2017-12-09 |
| First published | 2017-06-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 40 |
| Author | 321jiangtao@gmail.com |
| Maintainers | jerret321 |
| Keywords | webp, webpack, plugin |

## Links

- npm: https://www.npmjs.com/package/webp-webpack-plugin
- Repository: https://github.com/jiangtao/webp-webpack-plugin
- Homepage: https://github.com/jiangtao/webp-webpack-plugin#readme
- Issues: https://github.com/jiangtao/webp-webpack-plugin/issues
- npm.io page: https://npm.io/package/webp-webpack-plugin

## Dependencies (7)

- [sharp](https://npm.io/package/sharp.md) ^0.18.1
- [minify](https://npm.io/package/minify.md) ^3.0.1
- [semver](https://npm.io/package/semver.md) ^5.4.1
- [webpack](https://npm.io/package/webpack.md) ^3.10.0
- [file-type](https://npm.io/package/file-type.md) ^7.3.0
- [url-loader](https://npm.io/package/url-loader.md) ^0.6.2
- [file-loader](https://npm.io/package/file-loader.md) ^1.1.5

## 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

- 1.2.6 (latest) — 2017-12-09
- 1.2.5 — 2017-11-29
- 1.2.3 — 2017-11-29
- 1.2.2 — 2017-10-08
- 1.2.0 — 2017-10-08
- 1.0.1 — 2017-09-27
- 1.0.0 — 2017-09-21
- 0.2.0 — 2017-09-20
- 0.1.6 — 2017-09-20
- 0.1.5 — 2017-09-20
- 0.1.4 — 2017-09-20
- 0.1.3 — 2017-06-22
- 0.1.2 — 2017-06-22
- 0.1.1 — 2017-06-21
- 0.1.0 — 2017-06-21
- … 3 more at https://npm.io/package/webp-webpack-plugin/versions

## README

# webp-webpack-plugin

![Build Status](https://travis-ci.org/jiangtao/webp-webpack-plugin.svg?branch=master)
[![codecov](https://img.shields.io/codecov/c/github/jiangtao/webp-webpack-plugin.svg?style=flat-square)](https://codecov.io/gh/jiangtao/webp-webpack-plugin)
[![dependencies](https://img.shields.io/david/jiangtao/webp-webpack-plugin.svg?style=flat-square)](https://david-dm.org/jiangtao/webp-webpack-plugin)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/jiangtao/webp-webpack-plugin/master/LICENSE)

[简体中文文档](./README_zh-CN.md)

generate the webp image, make the same `hash` of original image. For example, `vue.e3e41b1.jpg` and `vue.e3e41b1.jpg.webp` exists at the same env.

## Install

```npm
npm i -D webp-webpack-plugin 
// or
yarn add -D webp-webpack-plugin
```

## Usage

in the webpack.config.js, the options `webp` refer to [sharp webp options](http://sharp.dimens.io/en/stable/api-output/#webp) 

```javascript
plugins: [
    new WebPWebpackPlugin({
        match: /(jpe?g|png)$/,
        webp: {
            quality: 80,
            inject: true, // inject the default runtime code
            injectCode: '' // inject your code
        }
    })
]
```

## WebPWebpackPlugin options

- match regexp that help plugin match the images need to transform to webp
- inject default false. When the value is false, not inject the runtime code. The priority level is lower than the option `injectCode`
- injectCode default ''. If the value is not empty, the priority level is more than the option `inject`
- limit default 0. If the image is smaller than the limit (in bytes) the image will not be transformed to webp
- checkStrict default false. Check the transformed image rule. If false, use the `match` options, else limit `png`, `jpeg`, `jpg` suffix image.
- format default `[name].[ext].webp`, another is `[name].webp`. In order to support more names.

tips： the inject runtime code help to replace the image src with webp format.


## principle

- webp transform 

change the webpack plugin `emit` and modify the  `compilation.assets` object, then generate the webp format image with the same hash as the original img src

- inject runtime code

Thanks to [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin) that support  [event hooks](https://github.com/jantimon/html-webpack-plugin#events)

## diff version webpack 

[diff version webpack comparison and configuration][https://github.com/jiangtao/webpack-diff-version-test]

## ChangeLog

- [2017-09-19] inject the code that can replace the img src by support webp and developers can inject your custom code
- [2017-10-05] add tests, travis, eslint and fix webpack2,3 bugs


## LICENSE

MIT

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