CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-html-minifier

Highly configurable, well-tested, JavaScript-based HTML minifier with extensive optimization options

86

1.17x
Overview
Eval results
Files

task.mdevals/scenario-6/

Batch HTML Minifier Runner

Create a small command-line helper that delegates to the HTML minifier CLI to process single files, STDIN/STDOUT streams, and whole directories. The helper must rely on the dependency's CLI binary (not its programmatic API) to apply minification behaviors defined in a supplied JSON config file.

Capabilities

Single-file minification

  • Given an input file that contains mixed indentation and an HTML comment, using a config that collapses whitespace and strips comments writes the minified output to the provided file path while preserving the doctype and inlining script tags onto one line, e.g., <!DOCTYPE html><html><body><p>Sale!</p><script>console.log(1)</script></body></html>. @test

STDIN to STDOUT pipeline

  • When invoked with source set to - (read from STDIN) and no output path, piping the same HTML as above through the helper produces the minified HTML on STDOUT using the config rules (collapsed whitespace, removed comments). @test

Directory batch processing

  • Running the helper with an input directory such as src/pages/index.html, src/pages/about.htm, and src/assets/logo.svg writes minified counterparts for the HTML/HTM files to the output directory, preserves relative paths, skips non-matching extensions (e.g., no output for the SVG), and applies the shared config to each processed file. @test

Implementation

@generates

API

export interface RunOptions {
  source: string;           // file path, directory path, or "-" for STDIN
  output?: string;          // file path, directory path, or undefined for STDOUT
  configPath: string;       // path to JSON config consumed by the underlying CLI
  extensions?: string[];    // file extensions to include when processing directories
}

export async function run(options: RunOptions): Promise<void>;

Dependencies { .dependencies }

html-minifier { .dependency }

Command-line HTML minifier used to process files, STDIN, and directories via its provided binary. @satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-html-minifier

tile.json