0.0.7 • Published 11 months ago

vite-plugin-html-template-element v0.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

vite-plugin-html-template-element

A Vite plugin to import HTML (*.tpl) files as HTMLTemplateElement.

Installation

npm install vite-plugin-html-template-element

Usage

Add the plugin to your Vite configuration:

import { defineConfig } from "vite";
import htmlTemplateElementPlugin from "vite-plugin-html-template-element";

export default defineConfig({
  plugins: [htmlTemplateElementPlugin()],
});

Then you can import HTML files as templates:

import myTemplate from "./my-template.tpl";

customElements.define(
  "my-custom-element",
  class extends HTMLElement {
    constructor() {
      super();

      const shadowRoot = this.attachShadow({ mode: "open" });
      shadowRoot.appendChild(myTemplate.content.cloneNode(true));
    }
  }
);

Required type declarations

Include the following declaration for typescript to recognize .tpl files.

declare module "*.tpl" {
  const template: HTMLTemplateElement;
  export default template;
}

License

MIT. This project is licensed under the MIT License - see the LICENSE file for details.

0.0.7

11 months ago

0.0.6

12 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago