JSPM

rollup-plugin-minify-html-parts

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q37283F
  • License MIT

Minify HTML in (tagged) template expressions

Package Exports

  • rollup-plugin-minify-html-parts
  • rollup-plugin-minify-html-parts/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rollup-plugin-minify-html-parts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

rollup-plugin-minify-html-parts

This library extracts (tagged) template expressions from TypeScript code, which will be minified when shouldMinify returns true.

Can be used in lit-html or fast-element.

Example

Rollup config

import { minifyHtmlParts } from "rollup-plugin-minify-html-parts";

export default {
  // ...
  plugins: [
    minifyHtmlParts({
      removeComments: true,
      removeAttributeQuotes: true,
      removeEmptyAttributeValues: true,
      shouldMinify(extractResult) {
        return extractResult.tag?.getText() === "html";
      },
    }),
  ],
};

Input

export const htmlResult = html`
  <my-element
    ${attr}
    id="${id}"
    class="x ${classes}"
    .property="${property}"
    @click="${onClick}"
  >
    <!-- comment -->
    ${html`
      <div>${textContent}</div>
    `}
  </my-element>
`;

Output

export const htmlResult = html`<my-element ${attr} id=${id} class="x ${classes}" .property=${property} @click=${onClick}> ${html`<div>${textContent}</div>`} </my-element>`;