image-minimizer
v0.0.3
Published
Image minimizer.
Downloads
5
Maintainers
Readme
image-minimizer
Image minimizer.
Install
yarn add image-minimizer --dev
Usage
Add image-minimizer
to your Vite config file.
import fs from 'node:fs/promises'
import path from 'node:path'
import minifyImages from 'image-minimizer'
const DIRECTORY = new URL('./path/to/directory/', import.meta.url)
let files = await fs.readdir(DIRECTORY, {withFileTypes: true, recursive: true})
files = await Promise.all(
files
.filter((dirent) => dirent.isFile())
.map(async (file) => ({
name: file.name,
content: await fs.readFile(path.join(file.path, file.name)),
})),
)
const compressed = await minifyImages(files)