From fcb47d8a60190dba1c6e3152f4462066b6040a5e Mon Sep 17 00:00:00 2001 From: JonasKruckenberg Date: Fri, 7 May 2021 16:27:40 +0200 Subject: [PATCH] docs: Add section explaining aync transforms to docs --- docs/guide/extending.md | 18 ++++++++++++++---- packages/core/package.json | 2 +- packages/rollup/package.json | 4 ++-- packages/vite/package.json | 4 ++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/docs/guide/extending.md b/docs/guide/extending.md index 07f456f0..99d6c1e8 100644 --- a/docs/guide/extending.md +++ b/docs/guide/extending.md @@ -12,10 +12,6 @@ The signature is as follows: type TransformFactory = (metadata: Partial, ctx: TransformFactoryContext) => ImageTransformation | undefined ``` -## Directive Context - - - ## Example Say you're using the following import statement very often @@ -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_ \ No newline at end of file diff --git a/packages/core/package.json b/packages/core/package.json index 6a23a10a..299fa0ac 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -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", diff --git a/packages/rollup/package.json b/packages/rollup/package.json index 05d94b5c..678faf8c 100644 --- a/packages/rollup/package.json +++ b/packages/rollup/package.json @@ -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", @@ -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": { diff --git a/packages/vite/package.json b/packages/vite/package.json index 33eb1021..76fcce5d 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -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", @@ -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": {