Skip to content

Commit

Permalink
docs: Add section explaining aync transforms to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKruckenberg committed May 7, 2021
1 parent da3e726 commit fcb47d8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
18 changes: 14 additions & 4 deletions docs/guide/extending.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ The signature is as follows:
type TransformFactory<A = {}> = (metadata: Partial<ImageConfig & A>, ctx: TransformFactoryContext) => ImageTransformation | undefined
```
## Directive Context
## Example
Say you're using the following import statement very often
Expand Down Expand Up @@ -83,6 +79,20 @@ We must also always return the transformed image.
> NOTE: The image object provided to the transform function is a sharp instance, so you have access to all it's methods as well.
### Asyn ImageTransform functions
![vite-imagetools v2.4.0 and newer](https://img.shields.io/badge/imagetools--core-^2.4.0-brightgreen) ![vite-imagetools v3.5.3 and newer](https://img.shields.io/badge/vite--imagetools-^3.5.3-brightgreen) ![rollup-plugin-imagetools v2.1.3](https://img.shields.io/badge/rollup--plugin--imagetools-^2.1.3-brightgreen)
Sometimes a transformation needs to perform some asynchronous action. To accommodate this, ImageTransform functions can return a promise that resolved with the sharp instance once the transformation is done.
```ts
function customDirective(): ImageTransform {
return async (image) => {
return longAsyncTask(image)
}
}
```
## Custom Output Formats
_TODO_
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imagetools-core",
"version": "2.3.3",
"version": "2.4.0",
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/rollup/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollup-plugin-imagetools",
"version": "2.1.2",
"version": "2.1.3",
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@rollup/pluginutils": "^4.1.0",
"imagetools-core": "^2.3.3",
"imagetools-core": "^2.4.0",
"magic-string": "^0.25.7"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vite-imagetools",
"description": "Load and transform images using a toolbox of import directives!",
"version": "3.5.2",
"version": "3.5.3",
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"@rollup/pluginutils": "^4.1.0",
"imagetools-core": "^2.3.3",
"imagetools-core": "^2.4.0",
"magic-string": "^0.25.7"
},
"devDependencies": {
Expand Down

0 comments on commit fcb47d8

Please sign in to comment.