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 🙏

© 2024 – Pkg Stats / Ryan Hefner

template-element-loader

v1.0.1

Published

A Webpack loader that serves your html contents into actual <template> elements

Downloads

3

Readme

<template>-element-loader

A webpack loader that lets you consume your HTML contents as actual <template> elements.

Why?

It allows preprocessing of the contents of your template to speed up subsequent rendering when needed by saving CPU cycles on HTML parsing.

It's only relevant at all if you reuse that template multiple times; harmless otherwise.

How-to

Usage example:

  • webpack.config.js:
rules: [{
  test: /\.template\.html$/,
  use: {
    loader: 'template-element-loader',
    options: {
      removeComments: true, // or any of the HTMLMinifier options
    },
  },
}]
  • my-component.template.html:
<div>
    <h2>Buttered Toast Recipe</h2>
    <ol type="I">
        <li>Choose your bread and place it in the toaster.</li>
        <li>Choose the toaster setting and set it off.</li>
        <li>Remove the toast.</li>
        <li>Butter your toast.</li>
    </ol>
</div>
  • my-component.controller.ts:
import template from './my-component.template.html';

class MyElement extends HTMLElement {

  constructor() {
    super()
      .attachShadow({ mode: 'closed' })
      .appendChild(template.content.cloneNode(true));
  }

}

Options

This loader additionally minifies your HTML content using HTMLMinifier.
You can refer to their Options Quick Reference table for guidance.

TypeScript typings

If your project uses TypeScript, we recommend you include something like the excerpt below to you typings:

  • declarations.d.ts:
declare module '*.html' {
  const template: HTMLTemplateElement;
  export default template;
}

Licensing

Uses the MIT license.

See LICENSE for the complete text or the MIT entry on TLDR Legal for a quick summary.