Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"libvips",
"hspace",
"commitlint",
"nodenext"
"nodenext",
"eslintcache"
],

"ignorePaths": [
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
.cache
coverage
.vscode
logs
Expand Down
103 changes: 103 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ with option `"markdown.extension.toc.levels": "2..6"`
- [Plugin Options](#plugin-options)
- [`test`](#test)
- [`include`](#include)
- [`cacheDir`](#cachedir)
- [`exclude`](#exclude)
- [`minimizer`](#minimizer)
- [Available minimizers](#available-minimizers)
Expand Down Expand Up @@ -76,6 +77,7 @@ with option `"markdown.extension.toc.levels": "2..6"`
- [`generator`](#generator-1)
- [Loader generator example for `imagemin`](#loader-generator-example-for-imagemin)
- [`severityError`](#severityerror-1)
- [`cacheDir`](#cachedir-1)
- [Additional API](#additional-api)
- [`imageminNormalizeConfig(config)`](#imageminnormalizeconfigconfig)
- [Examples](#examples)
Expand Down Expand Up @@ -699,6 +701,64 @@ module.exports = {
};
```

### `cacheDir`

Type:

```ts
type cacheDir = string;
```

Default: `undefined`

If provided, ensures all image transformations are done only once and cached within this folder. (Sharp only)

**webpack.config.js**

```js
const ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");

module.exports = {
optimization: {
minimizer: [
"...",
new ImageMinimizerPlugin({
cacheDir: ".cache/image-minimizer",
}),
],
},
};
```

### `bypassWebpackCache`

Type:

```ts
type bypassWebpackCache = string;
```

Default: `undefined`

If `true`, skips using Webpack's cache. (Typically useful if you're using the `cacheDir` and therefore don't need to double-up on caching with Webpack's cache.)

**webpack.config.js**

```js
const ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");

module.exports = {
optimization: {
minimizer: [
"...",
new ImageMinimizerPlugin({
bypassWebpackCache: true,
}),
],
},
};
```

### `minimizer`

Type:
Expand Down Expand Up @@ -2356,6 +2416,49 @@ module.exports = {
};
```

### `cacheDir`

Type:

```ts
type cacheDir = string;
```

Default: `undefined`

If provided, ensures all image transformations are done only once and cached within this folder. (Sharp only)

**webpack.config.js**

```js
const ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");

module.exports = {
module: {
rules: [
{
test: /\.(jpe?g|png|gif|svg)$/i,
type: "asset",
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
use: [
{
loader: ImageMinimizerPlugin.loader,
options: {
cacheDir: ".cache/image-minimizer",
minimizerOptions: {
plugins: ["gifsicle"],
},
},
},
],
},
],
},
};
```

## Additional API

### `imageminNormalizeConfig(config)`
Expand Down
74 changes: 70 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
"node": ">= 18.12.0"
},
"scripts": {
"start": "npm run build -- -w",
"start": "npm-run-all -p \"watch:**\"",
"clean": "del-cli dist types",
"prebuild": "npm run clean",
"build:types": "tsc --declaration --emitDeclarationOnly && prettier \"types/**/*.ts\" --write",
"build:types": "tsc --declaration --emitDeclarationOnly",
"postbuild:types": "prettier \"types/**/*.ts\" --write",
"build:code": "cross-env NODE_ENV=production babel src -d dist --copy-files",
"build": "npm-run-all -p \"build:**\"",
"watch:types": "npm run build:types -- -w",
"watch:code": "npm run build:code -- -w",
"commitlint": "commitlint --from=master",
"security": "npm audit --production",
"lint:prettier": "prettier --cache --list-different .",
Expand Down Expand Up @@ -69,8 +72,12 @@
}
},
"dependencies": {
"graceful-fs": "^4.2.11",
"mkdirp": "^3.0.1",
"proper-lockfile": "^4.1.2",
"schema-utils": "^4.2.0",
"serialize-javascript": "^6.0.2"
"serialize-javascript": "^6.0.2",
"stream-buffers": "^3.0.3"
},
"devDependencies": {
"@babel/cli": "^7.24.7",
Expand All @@ -79,10 +86,13 @@
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@squoosh/lib": "^0.5.3",
"@types/graceful-fs": "^4.1.9",
"@types/imagemin": "^9.0.0",
"@types/node": "^20.14.9",
"@types/proper-lockfile": "^4.1.4",
"@types/serialize-javascript": "^5.0.4",
"@types/sharp": "^0.32.0",
"@types/stream-buffers": "^3.0.7",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-jest": "^29.7.0",
"copy-webpack-plugin": "^12.0.2",
Expand Down
Loading
Loading