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

@islands/images

v0.10.0-beta.1

Published

<p align="center"> <a href="https://iles-docs.netlify.app"> <img src="https://github.com/ElMassimo/iles/blob/main/docs/images/banner.png"/> </a> </p>

Downloads

359

Readme

An îles module that configures vite-plugin-image-presets, allowing you to easily define presets to optimize and convert images:

  • 🖼 define presets once, apply everywhere

  • 🔗 use presets directly in img, source, and Picture

  • 🖥 customize formats, srcset, & sizes

  • ⚡️ on-demand in dev, cached at build time 📦

Demo 🖼 Source 💻

Configuration ⚙️

Add the module to iles.config.ts:

// iles.config.ts
import { defineConfig } from 'iles'

import images, { hdPreset } from '@islands/images'

export default defineConfig({
  modules: [
    images({
      thumnail: hdPreset({
        class: 'img thumb',
        loading: 'lazy',
        widths: [48, 96],
        formats: {
          webp: { quality: 44 },
          original: {},
        },
      }),
    }),
  ],
})

Usage 🚀

Use the preset query parameter to obtain an array of source and img attrs:

import thumbnails from '~/images/logo.jpg?preset=thumbnail'

expect(thumbnails).toEqual([
  {
    type: 'image/webp',
    srcset: '/assets/logo.ffc730c4.webp 48w, /assets/logo.1f874174.webp 96w',
  },
  {
    type: 'image/jpeg',
    srcset: '/assets/logo.063759b1.jpeg 48w, /assets/logo.81d93491.jpeg 96w',
    src: '/assets/logo.81d93491.jpeg',
    class: 'img thumb',
    loading: 'lazy',
  },
])

You can also use the src and srcset query parameters for direct usage:

import srcset from '~/images/logo.jpg?preset=thumbnail&srcset'

expect(srcset).toEqual('/assets/logo.063759b1.jpeg 48w, /assets/logo.81d93491.jpeg 96w')


import src from '~/images/logo.jpg?preset=thumbnail&src'

expect(src).toEqual('/assets/logo.81d93491.jpeg')

Images in Vue

A Picture Vue component is provided out of the box, which can receive any applied preset using the src prop, and renders a picture tag with the corresponding source and img tags.

<template>
  <Picture src="@/images/logo.jpg?preset=thumbnail"/>
</template>

Make sure to use an alias that starts with @, as Vue currently has a bug that does not transform certain relative imports.

Images in Markdown

The Picture component will be automatically used for any images in MDX, allowing you to use a preset while keeping the standard syntax:

![Landscape](~/images/mountains.jpg?preset=narrow)

Additionally, you can use markdown.withImageSrc to easily apply a preset to images referenced in MDX:

// iles.config.ts
import { defineConfig } from 'iles'

export default defineConfig({
  markdown: {
    withImageSrc (src, file) {
      // Example: If no preset was manually specified, use the `narrow` preset.
      if (!src.includes('?'))
        return `${src}?preset=narrow`
    },
  }
})

allowing you to keep the MDX cleaner:

![Landscape](~/images/mountains.jpg)