0.0.7 • Published 1 year ago

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

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year 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

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago