Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
vite-imagetools
Advanced tools
A toolbox of import directives for Vite that can transform your image at compile-time. All of the image transformations are powered by sharp.
npm install --save-dev vite-imagetools
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.
• 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: 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: string | RegExp | (string | RegExp)[]
Which paths to include when processing images.
default
/^[^?]+\.(heif|avif|jpeg|jpg|png|tiff|webp|gif)(\?.*)?$/
• removeMetadata: boolean
Wether to remove potentially private metadata from the image, such as exif tags etc.
default
true
▸ 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
[]
Name | Type |
---|---|
builtins | Record <string , OutputFormat > |
Record
<string
, OutputFormat
>
▸ 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
[]
Name | Type |
---|---|
builtins | TransformFactory <Record <string , unknown >>[] |
TransformFactory
<Record
<string
, unknown
>>[]
• Optional
resolveConfigs: (entries
: [string, string[]][]
, outputFormats
: Record
<string
,
OutputFormat
>) => Record<string, string | string[]>[]
▸ (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.
Name | Type | Description |
---|---|---|
entries | [string, string[]][] | The url parameter entries |
outputFormats | Record <string , OutputFormat > | - |
Record<string, string | string[]>[]
An array of directive options
Feel free to dive in! Open an issue or submit PRs! All information to get you started hacking on imagetools is in CONTRIBUTING.md!
FAQs
Load and transform images using a toolbox of import directives!
We found that vite-imagetools demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.