Skip to content

Commit

Permalink
feat: allow overiding sharp options
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Nov 12, 2020
1 parent 18b37a5 commit 7df04ca
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
9 changes: 8 additions & 1 deletion docs/content/en/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Internally nuxt image uses [ipx](https://github.com/nuxt-contrib/ipx) to modify
- `dir`: The root directory of the all images. By default nuxt image looks `static` dir to find original images,
- `clearCache`: The ipx has a caching stategy to clear cached images to reduce massive disk usages. You can schedule the cache cleaning job using `clearCache` option in provide options. By default this cron job is disabled.
- `cacheDir`: The directory to store the cached images.
- `sharp`: Modify default behavior of image opetimizer. Note that if you change this option, you need to clear ipx cache.

```js{}[nuxt.config.js]
export default {
Expand All @@ -147,7 +148,13 @@ export default {
/**
* Enable/Disable cache cleaning cron job
**/
clearCache: false
clearCache: false,
/**
* Modify default behavior of image optimizer
**/
sharp: {
// Here is complete list of available options: https://github.com/lovell/sharp/blob/master/lib/constructor.js#L132
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"defu": "^3.2.1",
"hasha": "^5.2.2",
"image-meta": "^0.0.1",
"ipx": "^0.4.0",
"ipx": "^0.4.1",
"node-fetch": "^2.6.1",
"upath": "^2.0.1"
},
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ function prepareLocalProvider ({ nuxt, options }, providerOptions) {
baseURL: `http://${defaultHost}:${defaultPort}${prefix}`,
dir: path.join('~', nuxt.options.dir.static),
clearCache: false,
cacheDir: '~~/node_modules/.cache/nuxt-image'
cacheDir: '~~/node_modules/.cache/nuxt-image',
sharp: {}
})

providerOptions.dir = nuxt.resolver.resolveAlias(providerOptions.dir)
Expand Down
3 changes: 2 additions & 1 deletion src/providers/ipx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ function createMiddleware (options) {
cache: {
dir: options.cacheDir,
cleanCron: options.clearCache
}
},
sharp: options.sharp
})
return IPXMiddleware(ipx)
}
3 changes: 3 additions & 0 deletions types/module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export interface ModuleOptions {
dir?: string;
clearCache?: boolean | string;
cacheDir?: string;
sharp: {
[key: string]: any;
}
}
sizes: number[],
internalUrl?: string
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6517,10 +6517,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.9.1.tgz#bff38543eeb8984825079ff3a2a8e6cbd46781b3"
integrity sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==

ipx@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/ipx/-/ipx-0.4.0.tgz#1a14402d473fb24972b2956f8840f8e208fdf54b"
integrity sha512-+1kAXuhU4vN0GcF2vDIxdYRP9D9E6wZuXWsZe+/7atM6MD26YG03JTrOAyo8Oa5OI7pZEZUAhDVKteghpJC3Tg==
ipx@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/ipx/-/ipx-0.4.1.tgz#747c221e1ec979247401f870de0f7afdeaf7837f"
integrity sha512-TxKdCKMo2eYUDK2Nbs0mAVQQuBmEuuB8oeToyajxMrzPj3aVoonAyo+m6b0XZufE5fBP1rCm+KSkOr0I5Qh70A==
dependencies:
connect "^3.7.0"
consola "^2.15.0"
Expand Down

0 comments on commit 7df04ca

Please sign in to comment.