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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mdream/vite

v0.15.3

Published

Vite plugin for HTML to Markdown conversion with on-demand generation

Readme

@mdream/vite

npm version npm downloads License

Vite plugin for HTML to Markdown conversion with on-demand generation support.

Features

  • 🚀 On-Demand Generation: Access any HTML page as .md for instant markdown conversion
  • 🤖 Smart Client Detection: Automatically serves markdown to LLM bots based on Accept headers
  • ⚡ Multi-Environment: Works in development, preview, and production
  • 📦 Build Integration: Generate static markdown files during build
  • 💾 Smart Caching: Intelligent caching for optimal performance
  • 🎯 URL Pattern Matching: Simple .md suffix for any HTML route
  • 🔧 Configurable: Full control over processing and output

Installation

pnpm add @mdream/vite

Usage

Add the plugin to your vite.config.js:

import { viteHtmlToMarkdownPlugin } from '@mdream/vite'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    viteHtmlToMarkdownPlugin({
      // Optional configuration
      include: ['**/*.html'],
      exclude: ['**/node_modules/**'],
      outputDir: 'markdown',
      cacheEnabled: true,
      mdreamOptions: {
        // mdream configuration options
        plugins: []
      }
    })
  ]
})

URL Pattern

The plugin enables accessing any HTML path with a .md extension:

  • /about/about.md (converts on-demand)
  • /docs/guide.html/docs/guide.md
  • /blog/post/blog/post.md

Smart Client Detection

The plugin automatically detects LLM bots and serves markdown without requiring the .md extension:

  • Serves markdown when Accept header contains */* or text/markdown (but not text/html)
  • Serves HTML to browsers (checks for text/html in Accept header or sec-fetch-dest: document)

This means LLM bots automatically receive optimized markdown responses, reducing token usage by ~10x compared to HTML.

Configuration Options

interface ViteHtmlToMarkdownOptions {
  /**
   * Glob patterns to include HTML files for processing
   * @default ['**\/*.html']
   */
  include?: string[]

  /**
   * Glob patterns to exclude from processing
   * @default ['*
   */node_modules/**
    ']
                  */
  exclude?: string[]

  /**
   * Output directory for generated markdown files
   * @default 'markdown'
   */
  outputDir?: string

  /**
   * Enable in-memory caching for development
   * @default true
   */
  cacheEnabled?: boolean

  /**
   * Options to pass to mdream's htmlToMarkdown function
   */
  mdreamOptions?: HtmlToMarkdownOptions

  /**
   * Whether to preserve directory structure in output
   * @default true
   */
  preserveStructure?: boolean

  /**
   * Custom cache TTL in milliseconds for production
   * @default 3600000 (1 hour)
   */
  cacheTTL?: number

  /**
   * Whether to log conversion activities
   * @default false
   */
  verbose?: boolean
}

How It Works

Development (vite dev)

  • Middleware: Intercepts .md requests via configureServer
  • Transform Pipeline: Uses Vite's transform system for HTML content
  • Fallbacks: Tries multiple path variations including SPA fallback
  • Caching: Memory cache with no-cache headers

Build Time (vite build)

  • Bundle Processing: Processes HTML files via generateBundle hook
  • Static Generation: Creates .md files alongside HTML output
  • Pattern Matching: Respects include/exclude patterns

Preview (vite preview)

  • File System: Reads from build output directory
  • Caching: Aggressive caching with TTL
  • Multiple Paths: Tries various file locations

Examples

Basic Setup

import { viteHtmlToMarkdownPlugin } from '@mdream/vite'

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

Advanced Configuration

import { viteHtmlToMarkdownPlugin } from '@mdream/vite'

export default defineConfig({
  plugins: [
    viteHtmlToMarkdownPlugin({
      include: ['pages/**/*.html', 'docs/**/*.html'],
      exclude: ['**/admin/**', '**/private/**'],
      outputDir: 'public/markdown',
      verbose: true,
      mdreamOptions: {
        plugins: [
          // Custom mdream plugins
        ]
      }
    })
  ]
})

With Custom mdream Options

import { viteHtmlToMarkdownPlugin } from '@mdream/vite'
import { readabilityPlugin } from 'mdream/plugins'

export default defineConfig({
  plugins: [
    viteHtmlToMarkdownPlugin({
      mdreamOptions: {
        plugins: [
          readabilityPlugin({
            minScore: 0.7
          })
        ]
      }
    })
  ]
})

Integration with SSR

For production SSR applications, you can extend your Express server:

import express from 'express'
import { createServer as createViteServer } from 'vite'

const app = express()

// In production, handle .md requests
app.use(async (req, res, next) => {
  if (req.path.endsWith('.md')) {
    // Your custom SSR markdown handling
    // The plugin provides the foundation
  }
  next()
})

License

MIT License