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

polymer-html-loader

v0.0.2

Published

A Webpack Loader that creates a Polymer Template from HTML files automatically

Downloads

4

Readme

polymer-html-loader

A loader for webpack that lets you "just import" the HTML into your JavaScript, and automatically create the Polymer Template for you. This is intended for Polymer 3.

Install:

npm install save-dev polymer-html-loader extract-loader

Or

yarn add polymer-html-loader extract-loader -D

Requirements

  • Polymer 3+ only!
  • Webpack 5

How this works:

  1. Include it in your Webpack Config. Include it "last" or after all the loaders. You will need to use extract-loader if you're using html-loader.
module.exports = {
  entry: './src/index.js',
  module: {
    rules: [
     {
        test: /\.(html)$/,
        use: [{
          loader: 'polymer-html-loader',
          options: {
            minify: true, // defaults to false
          },
        }, 'extract-loader', 'html-loader'],
      },
    ],
  },
};
  1. Include your .html file in your JavaScript:
import { PolymerElement } from '@polymer/polymer/polymer-element.js';

import template from './my-element.html';


class MyElement extends PolymerElement {

  static get template() {
    return template;
  }

  static get properties() {
    return {
      prop1: {
        type: String,
        value: 'polymer3-app',
      },
    };
  }
}

window.customElements.define('my-element', MyElement);

Options

|Name|Type|Default|Description| |:--:|:--:|:-----:|:----------| |minify|{Boolean}|false|When true, it will minify both the HTML and JavaScript output. |defaultSkip|{Boolean}|false|When true, it will not process files, unless explicitly included.

Files Parameters

These are appended at the end of the HTML imports in your JavaScript file (Where the component is declared); E.g:

import htmlString from './my-element.html?skip';

|Name|Type|Default|Description| |:--:|:--:|:-----:|:----------| |skip|{boolean}|N/A|Setting this parameter will skip processing altogether. This may be useful if you're using React and Polymer or you'd like to include the HTML without. E.g: import htmlString from './my-element.html?skip' |include|{boolean}|N/A|Setting this parameter will include the file for processing, even when defaultSkip is on. This may be useful if you just want to "polymerize" or "web-componentize" an .html file. E.g: import template from './my-element.html?include'. Note: include will take preference over defaultSkip.

Need an example?

Navigate to test-app, and execute: npm start. It will launch an express server @ localhost:3000. Then, run webpack. (Remember to have installed webpack-cli)

Why this loader

Writing HTML inside a JavaScript file is cumbersome and we lose autocomplete, and static analysis from our Text Editors and IDEs. Why not have an automatic way that creates these Polymer Templates for us?

Also, as of Polymer v3.5, using the 'html' template function as a regular javascript function (e.g html([htmlString])) is prohibited. This is due to v3.5's support for Trusted Types, which help prevent XSS attacks.

With this, you just include your .html template in your Polymer component, and you're set! The loader takes care for creating the file for you!

Ideas? Feedback?

Open a Github issue now! 😊