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

@cmorales_/vite-plugin-html-template

v2.1.0

Published

`@cmorales_/vite-plugin-html-template` is a plugin for vite and mainly for 'Vanilla' (without specific framework, like React.js, Vue, Svelte, ...), with witch you can define within the `<template>` tag as a component, then you can use the `<x-template>` t

Downloads

281

Readme

@cmorales_/vite-plugin-html-template

@cmorales_/vite-plugin-html-template is a plugin for vite and mainly for 'Vanilla' (without specific framework, like React.js, Vue, Svelte, ...), with which you can define within the <template> tag as a component, then you can use the <x-template> tag (customizable) and also add HTML attributes (class, data-*, style, aria-*)

Installation

  1. Install the package from npmjs.
	bun add @cmorales_/vite-plugin-html-template
	# or npm install ... or pnpm add ... or yarn add ...
  1. Import and add the plugin to the vite config.
import { defineConfig } from 'vite'
import htmlTemplate from '@cmorales_/vite-plugin-html-template'

export default defineConfig({
	plugins: [/*...plugins */ htmlTemplate({...})],
	//...vite config

})

Usage

  1. In your HTML define a <template> element with an unique id.

[!WARNING]

  1. The element <template> must have at least and at most 1 element.
  2. The attributes should be added to the element within the <template> tag and not to the <template> element itself.
   <!-- You should add attributes to the element within the <template> element -->
	 <template id="unique-id">
		<div class="..." ...other-attributes></div>
	 </template>
  1. Use the template with the <x-template> tag.

[!WARNING] You need add the data-template-id attribute to the <x-template> element referencing the same id as the <template> element to be used.

<x-template data-template-id="template-id"  class="..." style="..." ></x-template>
  1. Complete and working example

<!-- You can use it multiple times -->
<x-template data-template-id="primary-button-template" class="disabled-button" data-text="Press it"></x-template>
<x-template data-template-id="primary-button-template" data-text="Another button"></x-template>


<!-- You can add attributes to element within template element  -->
<template id="primary-button-template">
		<button class="primary-button" type="button">{text}</button>
</template>
  1. The result will be like:
<button class="primary-button disabled-button" type="button">Press it</button>	
<button class="primary-button" type="button">Another button</button>
	
<template id="primary-button-template">
		<button class="primary-button" type="button">{text}</button>
</template>

API

Template placeholders

You can inject dynamic values into your templates using placeholders.

To define a placeholder, use curly braces inside the template:

<template id="card">
  <div class="card">
    <h2>{title}</h2>
    <p>{description}</p>
  </div>
</template>

Then, pass values using data-* attributes in <x-template>:

<x-template 
  data-template-id="card"
  data-title="Hello world"
  data-description="This is a description"
></x-template>

Result

<div class="card">
  <h2>Hello world</h2>
  <p>This is a description</p>
</div>

Attribute merging

Attributes passed to <x-template> are merged into the root element of the template.

<x-template 
  data-template-id="card"
  class="highlight"
  style="color:red;"
></x-template>

Result

<div class="card highlight" style="color:red;">

Children Slot

You can use the special placeholder {children}

<x-template data-template-id="foo">
	<div> <!-- some children --> </div>
</x-template>

<template id="foo">
	<header>{children}</header>
</template>

Result

<header>
	<div> <!-- some children --> </div>
</header>

You can add html from a custom placeholder

<!-- You can use any html element -->
<x-template data-template-id="foo" data-text="Open Web" data-icon="<svg>...</svg>" ></x-template>


<template id="foo">
	<button type="button">
		{icon}
		<span>{text}</span>
	</button>
</template>

Result

<button>
	<svg>...</svg>
	<span>Open Web</span>
</button>

Supported attributes

You can pass any valid HTML attribute:

  • class
  • style
  • data-*
  • aria-*
  • etc.

[!NOTE]

  • Placeholder names must match the data-* attributes without the data- prefix.
  • If a placeholder is not provided, it will remain unchanged.

Plugin options

| Option | Type | Description | Default | | ------ | ------ | --------------------------------------------------------------------------- | -------------- | | tag | string | Custom tag name used to render template instances instead of <x-template> | "x-template" |

Contributing

[!NOTE] You need to have installed NodeJS

  1. Clone the repository
git clone https://github.com/Cristian-F-M/vite-plugin-html-template.git
  1. Install dependencies
npm install
# or bun install or pnpm install or ...
  1. Run test while you are coding
npm run test
# or bun run test or pnpm run test or ...

[!NOTE]

  1. You can add more test if your new features need it
  2. Ensure you pass all test before create a pull request
  3. Change the version in package.json file according to the changes (major, minor, patch)
npm version patch # minor or major	
# bun pm version patch # minor or major
# ...

About the Author

Created by Cristian Morales.

Support

If you find this tool useful, you can support my work!