
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
vite-plugin-html-include
Advanced tools
A Vite plugin to include HTML and SVG partials with variable interpolation and slot support.
A Vite plugin to include partial HTML files with variable interpolation and slot support — dead simple and fast.
<include file="..."> in your HTML files.html and .svg files by default<slot> and <slot name="..."> for dynamic blocks{{$name}}class and style like Vue.jsnpm install --save-dev vite-plugin-html-include
import { defineConfig } from 'vite'
import htmlInclude from 'vite-plugin-html-include'
export default defineConfig({
plugins: [
htmlInclude()
]
})
<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>
<div class="card">
<slot name="header"></slot>
<div class="body">
<h2>{{$title}}</h2>
<slot></slot>
</div>
<slot name="footer"></slot>
</div>
<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>
$var and data-$varYou can pass variables to an included component using either $var="..." or data-$var="...". Both methods are equivalent.
<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.
When the included component has a single root element:
class attributes are merged (like Vue)style attributes are merged with proper ; normalizationid, title, data-*) are injected<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>
If no content is passed, <slot> can define default content.
<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>
<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>
| 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
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>
MIT © Tilty.io
FAQs
A Vite plugin to include HTML and SVG partials with variable interpolation and slot support.
The npm package vite-plugin-html-include receives a total of 31 weekly downloads. As such, vite-plugin-html-include popularity was classified as not popular.
We found that vite-plugin-html-include demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.