Use imagemin to optimize your images in Snowpack. This plugin will only compress images in
production
after your build finishes.
npm i snowpack-plugin-imagemin
// snowpack.config.js
module.exports = {
plugins: [
[
'snowpack-plugin-imagemin',
{
/* see "Plugin Options" below */
include: ['**/*.jpg', '**/*.png'],
plugins: [
require('imagemin-mozjpeg')({quality: 90, progressive: true}),
require('imagemin-optipng')({optimizationLevel: 7}),
],
},
],
],
}
export interface SnowpackPluginImageminOptions {
/**
* Includes only the specified globs. Globs should be relative
* to the build directory, which is `build/` by default in Snowpack.
* *
* ! This option is required !
*/
include: Parameters<typeof imagemin>[0]
/**
* Plugins to use.
* @see https://www.npmjs.com/search?q=keywords:imageminplugin
*
* ! This option is required !
*/
plugins: imagemin.Options['plugins']
}
MIT