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

vite-plugin-html-include

v1.5.2

Published

A Vite plugin to include HTML and SVG partials with variable interpolation and slot support.

Readme

vite-plugin-html-include

A Vite plugin to include partial HTML files with variable interpolation and slot support — dead simple and fast.

npm license: MIT vite version


Features

  • Use <include file="..."> in your HTML files
  • Include .html and .svg files by default
  • Nested includes supported
  • Use <slot> and <slot name="..."> for dynamic blocks
  • Interpolate variables like {{$name}}
  • Merges class and style like Vue.js
  • All non-variable attributes are applied to the root element
  • Ultra fast and zero dependency
  • Automatic full-reload when included files change (dev only)

Install

npm install --save-dev vite-plugin-html-include

Usage

vite.config.ts

import { defineConfig } from 'vite'
import htmlInclude from 'vite-plugin-html-include'

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

Example

index.html

<include file="components/card.html" $title="Hello">
  <template slot="header">
    <h1>Custom header</h1>
  </template>

  <p>This is the main content</p>

  <template slot="footer">
    <footer>Custom footer</footer>
  </template>
</include>

components/card.html

<div class="card">
  <slot name="header"></slot>
  <div class="body">
    <h2>{{$title}}</h2>
    <slot></slot>
  </div>
  <slot name="footer"></slot>
</div>

Final Output

<div class="card">
    <h1>Custom header</h1>
    <div class="body">
        <h2>Hello</h2>
        <p>This is the main content</p>
    </div>
    <footer>Custom footer</footer>
</div>

Variables: $var and data-$var

You can pass variables to an included component using either $var="..." or data-$var="...". Both methods are equivalent.

Example

<include file="components/card.html" $title="Hello" />
<!-- is equivalent to -->
<include file="components/card.html" data-$title="Hello" />

In both cases, the variable $title will be injected into the component.


Class and Style Merging

When the included component has a single root element:

  • class attributes are merged (like Vue)
  • style attributes are merged with proper ; normalization
  • All other attributes (like id, title, data-*) are injected

Example

<include file="components/button.html" class="primary" style="color: red;" $text="Click me" title="action" />
<!-- components/button.html -->
<button class="btn" style="padding: 10px" title="{{$title}}">
  {{$text}}
</button>

Output:

<button class="btn primary" style="padding: 10px; color: red;" title="action">
  Click me
</button>

Default Slots

If no content is passed, <slot> can define default content.

components/card.html

<div class="card">
  <slot name="header">
    <h2>Default Header</h2>
  </slot>

  <div class="body">
    <slot>
      <p>Default content goes here</p>
    </slot>
  </div>

  <slot name="footer">
    <footer>Default Footer</footer>
  </slot>
</div>

Usage

<include file="components/card.html" />

Output:

<div class="card">
  <h2>Default Header</h2>
  <div class="body">
    <p>Default content goes here</p>
  </div>
  <footer>Default Footer</footer>
</div>

Options

| Option | Type | Default | Description | | --------------------|--------------------|---------------------|-------------------------------------------------| | extensions | string[] | ['.html', '.svg'] | Allowed file types | | delimiters | [string, string] | ['{{','}}'] | Variable interpolation delimiters | | allowAbsolutePaths | boolean | false | Allow absolute file paths | | watch | boolean | true | Auto-reload included files on change during dev |

When watch is enabled, you'll see logs like:

[vite-plugin-html-include] Reload detected: src/components/card.html

Advanced Usage: Custom Delimiters

If you want to use something other than {{ and }}, for example [[ and ]], you can configure it:

htmlInclude({ delimiters: ['[[', ']]'] })

In your HTML:

<div>Hello [[ $name ]]</div>

License

MIT © Tilty.io