Socket
Socket
Sign inDemoInstall

minify-literals

Package Overview
Dependencies
26
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    minify-literals

Minify CSS and HTML literals


Version published
Weekly downloads
2.9K
decreased by-31.12%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

minify-literals API Docs

Minify HTML & CSS markup inside JavaScript/TypeScript template literal strings.

Uses html-minifier-terser to minify HTML and clean-css to minify CSS.

Installation

$ npm i minify-literals
# or
$ yarn add minify-literals
# or
$ pnpm add minify-literals

Usage

TypeScript
import { minifyHTMLLiterals } from "minify-literals";

const source = `
		const el = html\`<div > <h1>  Hello World  </h1 > </div>\`;
		const css = css\` .foo { color: red; }  \`;
	`;

let { code, map } = await minifyHTMLLiterals(source);
// or with options: await minifyHTMLLiterals(source, { fileName: "test.js" });

console.log(code);
// const el = html`<div><h1>Hello World</h1></div>`;
// const css = css`.foo{color:red}`;

console.log(map);
// SourceMap {
//   "file": ".map",
//   "mappings": "AAAA;AACA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC, [...]
//   "names": [],
//   "sources": [
//     null,
//   ],
//   "sourcesContent": [
//     null,
//   ],
//   "version": 3,
// },

Options

export interface Options {
  /**
   * Minify HTML options, see https://github.com/terser/html-minifier-terser#options-quick-reference
   * @default .//src/defaultOptions.ts
   */
  minifyOptions?: Partial<minify.Options>;

  /**
   * Override the default strategy for how to minify HTML.
   * More info:
   *  https://github.com/explodingcamera/esm/blob/main/packages/minify-literals/lib/strategy.ts
   *
   * @optional
   */
  strategy: S;
}

Credits

This package is based on minify-html-literals by Elizabeth Mitchell I've fixed a few bugs, ported it to ES modules, and refactored it a bit.

Some of the fixed bugs:

Keywords

FAQs

Last updated on 15 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc