Skip to content

Commit

Permalink
feat: add imagemin plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Mar 31, 2020
1 parent 4b3304d commit 97f0a4a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/plugin-imagemin/index.js
@@ -0,0 +1,14 @@
// @see https://github.com/Klathmon/imagemin-webpack-plugin#api
exports.imagemin = {
test: /\.(svg|jpe?g|png|gif)$/i,
}

exports.webpack = function (config, env, opts) {
// disable during HMR/development
opts.imagemin.disable = !env.production;

if (!opts.imagemin.disable) {
const ImageMin = require('imagemin-webpack-plugin').default;
config.plugins.unshift(new ImageMin(opts.imagemin));
}
}
13 changes: 13 additions & 0 deletions packages/plugin-imagemin/package.json
@@ -0,0 +1,13 @@
{
"version": "0.0.0",
"name": "@pwa/plugin-imagemin",
"files": [
"index.js"
],
"engines": {
"node": ">=8"
},
"dependencies": {
"imagemin-webpack-plugin": "^2.4.0"
}
}
33 changes: 33 additions & 0 deletions packages/plugin-imagemin/readme.md
@@ -0,0 +1,33 @@
# @pwa/plugin-imagemin

> [`PWA`](https://pwa.cafe/) plugin for to compress image assets
## Install

```sh
$ npm install --save-dev @pwa/plugin-imagemin
```

## Usage

_None – recognized by and attached to `@pwa/core` automatically!_

> **Note:** Disabled during development (aka, `pwa watch`)
## Config

Configurable via the `imagemin` key on your `pwa.config.js` file.

***Default Config:***

> **Note:** In addition to the below, inherits `imagemin-webpack-plugin` defaults.
```js
exports.imagemin = {
test: /\.(svg|jpe?g|png|gif)$/i
}
```

***Available Options:***

See [`imagemin-webpack-plugin`](https://github.com/Klathmon/imagemin-webpack-plugin#api) for documentation.

0 comments on commit 97f0a4a

Please sign in to comment.