npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@macropygia/vite-plugin-imagemin-cache

v0.1.3

Published

Vite plugin to compress bundle and public images using imagemin. With persistent cache.

Downloads

24

Readme

@macropygia/vite-plugin-imagemin-cache

npm version MIT TypeScript Vite

English | 日本語

Vite plugin to compress static assets and public images using imagemin. With persistent cache.

  • This package is currently unstable.
    • Breaking changes may occur without any notice, even if in patch releases.
    • See CHANGELOG for changes.
  • This package only works as ESM.
    • "type": "module" is required in the package.json of the project using this plugin.

Installation

$ npm install @macropygia/vite-plugin-imagemin-cache

Usage

import { defineConfig } from 'vite'
import imageminPlugin from '@macropygia/vite-plugin-imagemin-cache'

export default defineConfig({
  plugins: [
    imageminPlugin({
      cacheDir: '.cache',
      concurrency: 4,
      plugins: {
        pngquant: { quality: [0.65, 1] },
        mozjpeg: { quality: 85 },
      }
    }),
  ],
})

Options

| Parameter | Type | Default | Required | | ------------------------ | -------------------- | ------------------------ | -------- | | cacheDir | string | node_modules/.imagemin | No | | expireDuration | number | 864000 (10 Days) | No | | countToExpire | number | 10 | No | | concurrency | number | os.cpus().length | No | | exclude | string \| string[] | | No | | plugins | object | {} | No | | asset.cachbuster | boolean \| string | false | No | | asset.useCrc | boolean | (Auto) | No | | asset.preventOverwrite | boolean | false | No | | public.preventDefault | boolean | false | No |

cacheDir

Set the cache directory.

  • The directory structure is as same as the destination.

expireDuration, countToExpire

Cache files will delete when the following conditions are satisfied.

  • The file did not use in the last countToExpire times of the build.
  • Over expireDuration seconds have passed since last used.

concurrency

The maximum concurrency of compressing.

exclude

Glob patterns to exclude from compression.

plugins

Imagemin plugin settings.

  • Following plugins are available with these extensions.
  • If the setting is empty, the plugin will run with its default settings.
  • If set to false , it will be disabled.
  • If settings about quality have changed, the cache must be cleared.

Example

plugins: {
  pngquant: { speed: 1, quality: [0.6, 1.0] },
  optipng: false, // Turn off
  mozjpeg: { quality: 85 },
  svgo: { plugins: [ ... ] },
},

asset.cachebuster (>= 0.1, experimental)

Add hash as a query string to attributes that references an image in HTML.

  • Only works with HTML.
  • If set true , join with ? .
    • /foo/bar.png -> /foo/bar.png?<hash>
    • /foo/baz.svg?q=123#id -> /foo/baz.svg?<hash>&q=123#id
  • If set string , join with the string.
    • /foo/bar.png -> /foo/bar.png<string><hash>
    • /foo/baz.svg?q=123#id -> /foo/baz.svg<string><hash>&q=123#id

asset.useCrc (>= 0.1, experimental)

If set true , the plugin process static assets in the same way as the public directory.

  • Normally, no need to use.
  • This is prepared for complex settings in rollupOptions.output.assetFileNames .
    • Set to true if [hash] is not included in assetFileNames.

asset.preventOverwrite (>= 0.1, experimental)

If the file with the same name exists in the output directory, skip copying from the cache.

  • Do not use this option if the file name of static assets doesn't contain [hash] .
  • No need to enable this option unless handling a huge number of images.
  • Disable automatically when emptyOutDir is true .

public.preventDefault (>= 0.1, experimental)

Stop Vite's default copy process for the public directory and copy compressed images and the others separately.

  • By default, compressed images are overwritten after Vite copies all files in the public directory.
  • This option will change true by default in a future release.