An esbuild plugin for minimizing images using imagemin
yarn add -D esbuild-plugin-imagemin
# or
npm install --save-dev esbuild-plugin-imagemin
const esbuild = require("esbuild");
const imageminPlugin = require("esbuild-plugin-imagemin");
esbuild.build({
plugins: [imageminPlugin()],
});
ESM import is also included.
The plugin works with png, jpg, gif and svg.
By default this plugin uses:
interface ImageminPluginOptions {
disableDefaultPlugins?: {
mozjpeg?: boolean,
pngquant?: boolean,
svgo?: boolean,
gifsicle?: boolean,
};
defaultPluginsOptions?: {
mozjpeg?: mozjpeg.Options,
pngquant?: pngquant.Options,
svgo?: svgo.Options,
gifsicle?: gifsicle.Options,
};
plugins?: Array<(input: Buffer) => Promise<Buffer>>;
}
You can disable some(or even all) of default plugins by passing their names inside disableDefaultPlugins
with true value
// only svgo and pngquant will work
esbuild.build({
plugins: [
imageminPlugin({
disableDefaultPlugins: {
mozjpeg: true,
gifsicle: true,
},
}),
],
});
You can pass options inside default plugins. You can find the options format in plugins documentation.
esbuild.build({
plugins: [
imageminPlugin({
defaultPluginsOptions: {
mozjpeg: {
quality: 50,
},
},
}),
],
});
You can pass any other imagemin plugins with options
const imageminOptipng = require("imagemin-optipng");
esbuild.build({
plugins: [
imageminPlugin({
plugins: [imageminOptipng({ optimizationLevel: 5 })],
}),
],
});