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

vite-plugin-svg-in-og-image

v0.1.0

Published

A Vite plugin that automatically converts SVG files used in og:image meta tags to PNG format

Downloads

15

Readme

vite-plugin-svg-in-og-image

A Vite plugin that automatically converts SVG files used in og:image meta tags to PNG format. This is essential for social media platforms that don't support SVG images in Open Graph meta tags.

Why?

Most social media platforms (Facebook, Twitter, LinkedIn, etc.) don't support SVG images in og:image meta tags. They require raster formats like PNG or JPEG. This plugin automatically detects SVG files referenced in your HTML meta tags and converts them to PNG behind the scenes.

Features

  • 🚀 Automatic Detection: Scans your HTML for SVG files in meta tags
  • 🔄 Seamless Conversion: Converts SVG to PNG using Sharp for high quality
  • 📁 Organized Output: Creates a dedicated directory for converted images
  • Build Integration: Works seamlessly with Vite's build process
  • 🎛️ Configurable: Multiple options for customization
  • 📝 TypeScript Support: Full TypeScript support with type definitions

Installation

npm install vite-plugin-svg-in-og-image
# or
yarn add vite-plugin-svg-in-og-image
# or
pnpm add vite-plugin-svg-in-og-image

Usage

Basic Setup

// vite.config.ts
import { defineConfig } from 'vite'
import svgInOgImage from 'vite-plugin-svg-in-og-image'

export default defineConfig({
  plugins: [
    svgInOgImage()
  ]
})

HTML Usage

<!DOCTYPE html>
<html>
<head>
  <!-- This SVG will be automatically converted to PNG -->
  <meta property="og:image" content="/images/social-card.svg" />
  <meta name="twitter:image" content="/images/twitter-card.svg" />
</head>
<body>
  <!-- Your content -->
</body>
</html>

After the build, the plugin will:

  1. Convert /images/social-card.svg to /images/og-images/social-card.png
  2. Update the HTML to reference the PNG files instead
  3. The final HTML will contain: <meta property="og:image" content="/images/og-images/social-card.png" />

Configuration

// vite.config.ts
import { defineConfig } from 'vite'
import svgInOgImage from 'vite-plugin-svg-in-og-image'

export default defineConfig({
  plugins: [
    svgInOgImage({
      // Directory where SVG files are located (relative to project root)
      inputDir: 'public', // default: 'public'
      
      // Directory where converted PNG files will be saved (relative to inputDir)
      outputDir: 'og-images', // default: 'og-images'
      
      // PNG compression quality (0-100)
      quality: 90, // default: 90
      
      // Whether to log conversion progress
      verbose: true, // default: true
      
      // Custom regex pattern to match SVG files in HTML
      svgPattern: /content="([^"]*\.svg)"/g // default pattern
    })
  ]
})

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | inputDir | string | 'public' | Directory where SVG files are located (relative to project root) | | outputDir | string | 'og-images' | Directory where converted PNG files will be saved (relative to inputDir) | | quality | number | 90 | PNG compression quality (0-100) | | verbose | boolean | true | Whether to log conversion progress | | svgPattern | RegExp | /content="([^"]*\.svg)"/g | Custom regex pattern to match SVG files in HTML |

How It Works

  1. Detection Phase: The plugin scans your HTML files during the build process
  2. Pattern Matching: It looks for SVG files referenced in content attributes (typically in meta tags)
  3. Conversion: Found SVG files are converted to PNG format using Sharp
  4. Path Replacement: The HTML is updated to reference the new PNG files
  5. File Organization: Converted files are saved in the specified output directory

File Structure

your-project/
├── public/
│   ├── images/
│   │   ├── social-card.svg      # Original SVG
│   │   └── og-images/           # Created by plugin
│   │       └── social-card.png  # Converted PNG
│   └── index.html
└── vite.config.ts

Supported Patterns

The plugin automatically detects SVG files in these common meta tag patterns:

  • <meta property="og:image" content="/path/to/image.svg" />
  • <meta name="twitter:image" content="/path/to/image.svg" />
  • <meta name="twitter:image:src" content="/path/to/image.svg" />
  • Any other meta tag with content="path/to/file.svg"

Requirements

  • Node.js >= 18
  • Vite >= 4.0.0

Dependencies

  • Sharp: Used for high-quality SVG to PNG conversion
  • Vite: Peer dependency for plugin integration

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Issues

If you encounter any issues, please file them at: GitHub Issues