esbuild-plugin-imagemin
An esbuild plugin for minimizing images using imagemin
Install
yarn add -D esbuild-plugin-imagemin
# or
npm install --save-dev esbuild-plugin-imagemin
Usage
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:
Configuration
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>>;
}
disableDefaultPlugins
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,
},
}),
],
});
defaultPluginsOptions
You can pass options inside default plugins. You can find the options format in plugins documentation.
esbuild.build({
plugins: [
imageminPlugin({
defaultPluginsOptions: {
mozjpeg: {
quality: 50,
},
},
}),
],
});
plugins
You can pass any other imagemin plugins with options
const imageminOptipng = require("imagemin-optipng");
esbuild.build({
plugins: [
imageminPlugin({
plugins: [imageminOptipng({ optimizationLevel: 5 })],
}),
],
});