7.0.2 • Published 11 days ago

vite-imagetools v7.0.2

Weekly downloads
97
License
MIT
Repository
github
Last release
11 days ago

vite-imagetools

npm (latest) standard-readme compliant codecov

A toolbox of import directives for Vite that can transform your image at compile-time. All of the image transformations are powered by sharp.

Features

  • 🚀 Output modern formats
  • 🖼 Resize Images
  • 🔗 Easy Srcset generation
  • ⚡️ Fast in development mode
  • 🔒 Remove Image Metadata
  • 🧩 Extensible

Read the docs to learn more!

Table of Contents

Install

npm install --save-dev vite-imagetools

Usage

import { defineConfig } from 'vite'
import { imagetools } from 'vite-imagetools'

export default defineConfig({
  plugins: [imagetools()]
})
import Image from 'example.jpg?w=400&h=300&format=webp'

You can also import a directory of images using Vite's import.meta.glob with its query option.

Options

defaultDirectives

Optional defaultDirectives: URLSearchParams | (url: URL) => URLSearchParams

This option allows you to specify directives that should be applied by default to every image. You can also provide a function, in which case the function gets passed the asset ID and should return an object of directives. This can be used to define all sorts of shorthands or presets.

example

import { defineConfig } from 'vite'
import { imagetools } from 'vite-imagetools'

export default defineConfig({
  plugins: [
    imagetools({
      defaultDirectives: (url) => {
        if (url.searchParams.has('spotify')) {
          return new URLSearchParams({
            tint: 'ffaa22'
          })
        }
        return new URLSearchParams()
      }
    })
  ]
})

exclude

exclude: string | RegExp | (string | RegExp)[]

What paths to exclude when processing images. This defaults to the public dir to mirror Vite's behavior.

default 'public\/**\/*'


include

include: string | RegExp | (string | RegExp)[]

Which paths to include when processing images.

default /^[^?]+\.(heif|avif|jpeg|jpg|png|tiff|webp|gif)(\?.*)?$/


removeMetadata

removeMetadata: boolean

Wether to remove potentially private metadata from the image, such as exif tags etc.

default true


extendOutputFormats

Optional extendOutputFormats(builtins): Record<string, OutputFormat>

You can use this option to extend the builtin list of output formats. This list will be merged with the builtin output formats before determining the format to use.

default []

Parameters

NameType
builtinsRecord<string, OutputFormat>

Returns

Record<string, OutputFormat>


extendTransforms

Optional extendTransforms(builtins): TransformFactory<Record<string, unknown>>[]

You can use this option to extend the builtin list of import transforms. This list will be merged with the builtin transforms before applying them to the input image.

default []

Parameters

NameType
builtinsTransformFactory<Record<string, unknown>>[]

Returns

TransformFactory<Record<string, unknown>>[]


resolveConfigs

Optional resolveConfigs: (entries: [string, string[]][], outputFormats: Record<string, OutputFormat>) => Record<string, string | string[]>[]

Type declaration

▸ (entries, outputFormats): Record<string, string | string[]>[]

This function builds up all possible combinations the given entries can be combined an returns it as an array of objects that can be given to a the transforms.

Parameters
NameTypeDescription
entries[string, string[]][]The url parameter entries
outputFormatsRecord<string, OutputFormat>-
Returns

Record<string, string | string[]>[]

An array of directive options

Contributing

Feel free to dive in! Open an issue or submit PRs! All information to get you started hacking on imagetools is in CONTRIBUTING.md!

License

MIT © Jonas Kruckenberg.

7.0.2

11 days ago

7.0.1

1 month ago

7.0.0

1 month ago

6.2.9

4 months ago

6.2.8

5 months ago

6.1.0

7 months ago

6.2.5

6 months ago

6.2.4

6 months ago

6.2.7

5 months ago

6.2.6

5 months ago

6.2.1

6 months ago

6.2.0

6 months ago

6.2.3

6 months ago

6.2.2

6 months ago

6.0.0

7 months ago

5.1.2

7 months ago

5.1.1

7 months ago

5.1.0

7 months ago

5.0.9

7 months ago

5.0.8

9 months ago

5.0.7

10 months ago

5.0.6

10 months ago

5.0.5

10 months ago

4.0.19

1 year ago

4.0.16

1 year ago

4.0.15

1 year ago

4.0.18

1 year ago

4.0.17

1 year ago

5.0.4

12 months ago

5.0.3

1 year ago

5.0.2

1 year ago

5.0.1

1 year ago

5.0.0

1 year ago

4.0.10

2 years ago

4.0.12

1 year ago

4.0.11

2 years ago

4.0.14

1 year ago

4.0.13

1 year ago

4.0.5

2 years ago

4.0.7

2 years ago

4.0.6

2 years ago

4.0.9

2 years ago

4.0.8

2 years ago

4.0.4

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

4.0.1

2 years ago

4.0.0

3 years ago

3.9.0

3 years ago

3.8.0

3 years ago

3.7.0

3 years ago

3.5.4

3 years ago

3.6.2

3 years ago

3.4.4

3 years ago

3.6.1

3 years ago

3.4.3

3 years ago

3.6.0

3 years ago

3.4.2

3 years ago

3.4.1

3 years ago

3.6.6

3 years ago

3.6.5

3 years ago

3.6.4

3 years ago

3.6.3

3 years ago

3.6.8

3 years ago

3.6.7

3 years ago

3.5.2

3 years ago

3.5.1

3 years ago

3.5.0

3 years ago

3.4.0

3 years ago

3.4.0-next.7

3 years ago

3.4.0-next.6

3 years ago

3.4.0-next.5

3 years ago

3.4.0-next.4

3 years ago

3.4.0-next.3

3 years ago

3.4.0-next.2

3 years ago

3.4.0-next.1

3 years ago

3.4.0-next.0

3 years ago

3.3.2-alpha.0

3 years ago

3.3.1

3 years ago

3.3.0

3 years ago

3.2.2

3 years ago

3.2.6

3 years ago

3.2.4

3 years ago

3.0.0-next.11

3 years ago

3.0.0-next.10

3 years ago

3.0.0-next.13

3 years ago

3.0.0-next.12

3 years ago

3.0.0-next.2

3 years ago

3.0.0-next.1

3 years ago

3.0.0-next.4

3 years ago

3.0.0-next.3

3 years ago

3.0.0-next.15

3 years ago

3.0.0-next.14

3 years ago

3.0.0-next.9

3 years ago

3.0.0-next.6

3 years ago

3.0.0-next.5

3 years ago

3.0.0-next.8

3 years ago

3.0.0-next.7

3 years ago

3.0.2

3 years ago

3.1.0

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.4.0-next.1

3 years ago

2.3.3

3 years ago

2.3.2

3 years ago

2.3.1

3 years ago

2.3.0

3 years ago