Image minimizer.
yarn add image-minimizer --dev
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)
console.log(compressed)
// -> [<Buffer ...>, ...]
Type: boolean
Default: true
Enables cache.
Type: 'error' | 'warn' | 'ignore' | (file) => void
Default: 'error'
Executes when file extension doesn't match actual file type.