snowpack-plugin-minify-html-literals
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

snowpack-plugin-minify-html-literals

npm version Codacy Badge Codacy Badge Node.js CI CodeQL

snowpack-plugin-minify-html-literals is a snowpack plugin to minify HTML template literal strings, using minify-html-literals.

Installation

npm install -D snowpack-plugin-minify-html-literals

Usage

Tagged templates

// snowpack.config.mjs
export default {
  plugins: ['snowpack-plugin-minify-html-literals'],
};
// index.js
const html = (strings) => strings.raw[0];
const template = html`
  <div>
    <p>Hello, World!</p>
  </div>
`;

const body = document.querySelector('body');
body.innerHTML = template;
// A transformation result of index.js
const html = (strings) => strings.raw[0];
const template = html`<div><p>Hello, World!</p></div>`;

const body = document.querySelector('body');
body.innerHTML = template;

Non-tagged templates

// snowpack.config.mjs
export default {
  plugins: [[
    'snowpack-plugin-minify-html-literals',
    {
      options: {
        shouldMinify: (template) => {
          return template.parts.some(part => part.text.includes('data-minify="true"'));
        },
      },
    },
  ]],
};
// index.js
const template = `
  <div data-minify="true">
    <p>Hello, World!</p>
  </div>
`;

const body = document.querySelector('body');
body.innerHTML = template;
// A transformation result of index.js
const template = `<div data-minify="true"><p>Hello, World!</p></div>`;

const body = document.querySelector('body');
body.innerHTML = template;

Options

// snowpack.config.mjs
export default {
  plugins: [[
    'snowpack-plugin-minify-html-literals',
    {
      options: null, // minify-html-literals options. See https://github.com/asyncLiz/minify-html-literals#options
      exts: ['.js', '.mjs', '.ts'], // target file extensions
    }
  ]],
};

Package Sidebar

Install

npm i snowpack-plugin-minify-html-literals

Weekly Downloads

4

Version

0.1.1

License

Apache-2.0

Unpacked Size

21.8 kB

Total Files

9

Last publish

Collaborators

  • akiomik