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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rokka-io/nuxt

v1.0.2

Published

Render responsive images with rokka.io in Nuxt 3

Readme

Responsive images with rokka for Nuxt 3

Setup

npm install --save @rokka-io/nuxt

Minimal configuration:

export default defineNuxtConfig({
  modules: ['@rokka-io/nuxt'],

  rokka: {
    host: 'rokka-demos.rokka.io',
    viewports: {
      sm: 768,
      md: 1024,
      lg: 1280,
      xl: 1680,
    },
  },
})

Create stacks

You need two rokka stacks to make the responsive images work:

  • fe_nuxt_crop: For cropped images where both width and height are set
  • fe_nuxt_no_crop: For images where only the width is scaled (without cropping)

You can find example stack configurations in the ./stacks folder.

Render an image

Use the <RokkaImage> component to render a single rokka image. The hash and config props are required.

<template>
  <RokkaImage hash="90b93a" :config="imageStyle" />
</template>

Define image styles

You can define three types of image styles using the defineImageStyle() composable:

<picture> element with <source>

const imageStyle = defineImageStyle({
  type: 'pictures',
  pictures: {
    // Force 375px width in a specific aspect ratio and crop image.
    sm: {
      width: 375,
      aspectRatio: 16 / 9,
    },
    // Force exact dimensions and crop image.
    lg: {
      width: 1024,
      height: 300,
    },
    // Force width of 1680px without cropping the image.
    xl: {
      width: 1680,
    },
  },
})

<img> element with srcset and sizes attributes

// Crop image to a 16/9 aspect ratio.
const crop = defineImageStyle({
  type: 'sizes',
  aspectRatio: 16 / 9,
  sizes: {
    sm: 375,
    md: 768,
    lg: 980,
    xl: 1200,
  },
})

// Keep aspect ratio of original image.
const noCrop = defineImageStyle({
  type: 'sizes',
  sizes: {
    sm: 375,
    md: 768,
    lg: 980,
    xl: 1200,
  },
})

<img> element with a single src attribute

// Crop image to exactly 400x400.
const crop = defineImageStyle({
  type: 'single',
  width: 400,
  height: 400,
})

// Crop image to a width of 400px and calculate height based on aspect ratio
const cropAspect = defineImageStyle({
  type: 'single',
  aspectRatio: 16 / 9,
  width: 400,
})

// Crop image to a width of 400px and calculate height based on aspect ratio
const cropAspect = defineImageStyle({
  type: 'single',
  aspectRatio: 16 / 9,
  width: 400,
})

Custom stack

You can also render a single image in a custom rokka stack by passing the name of an existing stack to the config prop:

<template>
  <RokkaImage hash="90b93a" config="name_of_custom_stack" />
</template>

Configuration

The following configuration options are available via nuxt.config.ts:

host: string

The rokka host to use, e.g. rokka-demos.rokka.io.

viewports: Record<string, number>

Define the viewport keys and their screen min-width media value. If your define something like this:

{
  "xs": 0,
  "md": 768,
  "lg": 1024
}

This will make it possible to define three different set of sizes per viewport.

dpr: string[]

Define the DPR (device pixel ratios). If you set something like:

["", "1.5", "2"]

Then all generated images will have three variants, one for < 1.5 DPR, one for 1.5 and one for > 2.0.

stacks: { crop: string, noCrop: string }

By default, the module assumes two stacks with name fe_nuxt_crop and fe_nuxt_no_crop. You can override this globally and define your own stack names.