@icon-magic/imagemin-farm
A process farm for image minification! Has two main methods exported:
minify(path: string): Promise<Result>
Given a path to a png
, jpg
, or webp
file, minify the file. File will be modified in-place and replaced with the minified version of the file. Spins up os.cpus() - 1
child processes to minify files. Minification tasks are transparently load balanced between processes. Promise will resolve with a Result
object of the shape:
interface Result {
path: 'path-to-file';
worker: number;
status: {
total: number;
remaining: number;
progress: number;
workers: [
{
pid: number;
total: number;
remaining: number;
progress: number | null;
}
];
};
}
subscribe(func: (res: ProcessStatus) => void): void
Subscribe a listener to recieve regular updates on process status. Good for updating progress bars. Recieves the status
property of the Results
object (defined above).