or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-swc--html-darwin-arm64

Super-fast HTML minifier native binary for macOS ARM64 (Apple Silicon)

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@swc/html-darwin-arm64@1.13.x

To install, run

npx @tessl/cli install tessl/npm-swc--html-darwin-arm64@1.13.0

index.mddocs/

@swc/html-darwin-arm64

@swc/html-darwin-arm64 is a platform-specific native binary package for macOS ARM64 (Apple Silicon) that provides super-fast HTML minification capabilities. This package contains a compiled Rust binary that implements high-performance HTML parsing, minification, and optimization features as part of the SWC (Speedy Web Compiler) ecosystem.

Package Information

  • Package Name: @swc/html-darwin-arm64
  • Package Type: npm
  • Language: Rust (compiled to N-API native module)
  • Installation: Automatically installed as dependency of @swc/html on macOS ARM64 systems
  • Platform: macOS (darwin) ARM64 only
  • Main Binary: swc-html.darwin-arm64.node

Core Imports

This package is a platform-specific native dependency and is not used directly. Instead, it provides native implementation for the @swc/html package APIs. Import from the main package:

import { minify, minifySync, minifyFragment, minifyFragmentSync, type Options, type FragmentOptions } from "@swc/html";

For CommonJS:

const { minify, minifySync, minifyFragment, minifyFragmentSync } = require("@swc/html");

Note: The @swc/html-darwin-arm64 package is automatically selected as a dependency on macOS ARM64 systems and cannot be imported directly. Type definitions for TransformOutput, Element, Attribute, and Diagnostic are available from function return types.

Basic Usage

import { minify, type Options } from "@swc/html";

// Basic HTML minification
const result = await minify(`
  <html>
    <head>
      <title>  Example Page  </title>
    </head>
    <body>
      <!-- This is a comment -->
      <p class="text">  Hello World!  </p>
    </body>
  </html>
`);

console.log(result.code); // Minified HTML

// With configuration options
const options: Options = {
  collapseWhitespaces: "smart",
  removeComments: true,
  removeEmptyAttributes: true,
  minifyJs: true,
  minifyCss: true
};

const minified = await minify(htmlContent, options);

Architecture

The @swc/html-darwin-arm64 package provides native performance through:

  • N-API Integration: Rust binary compiled to Node.js native addon
  • Platform Detection: Automatically loaded on macOS ARM64 systems via @swc/html
  • High Performance: Memory-efficient HTML parsing and minification in Rust
  • Zero JavaScript API: All functionality exposed through parent @swc/html package

Capabilities

HTML Minification

Core HTML minification functionality with extensive configuration options for whitespace handling, comment removal, and attribute optimization.

/**
 * Asynchronously minifies HTML content with options
 * @param content - HTML content as string or Buffer  
 * @param options - Optional minification configuration
 * @returns Promise resolving to TransformOutput with minified code
 */
function minify(
  content: string | Buffer,
  options?: Options
): Promise<TransformOutput>;

/**
 * Synchronously minifies HTML content with options
 * @param content - HTML content as string or Buffer
 * @param options - Optional minification configuration  
 * @returns TransformOutput with minified code
 */
function minifySync(
  content: string | Buffer,
  options?: Options
): TransformOutput;

Fragment Minification

HTML fragment minification with parsing context support for handling partial HTML documents.

/**
 * Asynchronously minifies HTML fragment with context options
 * @param content - HTML fragment as string or Buffer
 * @param options - Optional fragment-specific configuration
 * @returns Promise resolving to TransformOutput with minified fragment
 */
function minifyFragment(
  content: string | Buffer,
  options?: FragmentOptions
): Promise<TransformOutput>;

/**
 * Synchronously minifies HTML fragment with context options  
 * @param content - HTML fragment as string or Buffer
 * @param options - Optional fragment-specific configuration
 * @returns TransformOutput with minified fragment
 */
function minifyFragmentSync(
  content: string | Buffer,
  options?: FragmentOptions
): TransformOutput;

Types

Core Types

interface TransformOutput {
  /** Minified HTML content */
  code: string;
  /** Optional array of diagnostic messages */
  errors?: Array<Diagnostic>;
}

interface Diagnostic {
  /** Diagnostic level (error, warning, etc.) */
  level: string;
  /** Diagnostic message text */
  message: string;
  /** Source location span information */
  span: any;
}

type MinifierType = "js-module" | "js-script" | "json" | "css" | "html";

Configuration Types

interface Options {
  /** Input filename for error reporting */
  filename?: string;
  /** Whether content is from iframe srcdoc */
  iframeSrcdoc?: boolean;
  /** Whether scripting is enabled during parsing */
  scriptingEnabled?: boolean;
  /** Force HTML5 doctype */
  forceSetHtml5Doctype?: boolean;
  
  /** Whitespace collapse strategy */
  collapseWhitespaces?:
    | "none"
    | "all" 
    | "smart"
    | "conservative"
    | "advanced-conservative"
    | "only-metadata";
  
  /** Remove empty metadata elements */
  removeEmptyMetadataElements?: boolean;
  /** Remove HTML comments */
  removeComments?: boolean;
  /** Preserve specific comments matching patterns */
  preserveComments?: string[];
  /** Minify conditional comments */
  minifyConditionalComments?: boolean;
  
  /** Remove empty attributes */
  removeEmptyAttributes?: boolean;
  /** Remove redundant attributes */
  removeRedundantAttributes?: "none" | "all" | "smart";
  /** Collapse boolean attributes */
  collapseBooleanAttributes?: boolean;
  /** Normalize attribute formatting */
  normalizeAttributes?: boolean;
  
  /** Minify JSON content in script tags */
  minifyJson?: boolean | { pretty?: boolean };
  /** Minify JavaScript content in script tags */
  minifyJs?: boolean | { parser?: any; minifier?: any; codegen?: any };
  /** Minify CSS content in style tags */
  minifyCss?:
    | boolean
    | { lib: "lightningcss" }
    | { lib: "swc"; parser?: any; minifier?: any; codegen?: any };
  
  /** Minify additional script content by type */
  minifyAdditionalScriptsContent?: [string, MinifierType][];
  /** Minify additional attributes by type */
  minifyAdditionalAttributes?: [string, MinifierType][];
  
  /** Sort space-separated attribute values */
  sortSpaceSeparatedAttributeValues?: boolean;
  /** Sort attributes alphabetically */
  sortAttributes?: boolean;
  /** Omit optional HTML tags */
  tagOmission?: boolean | "keep-head-and-body";
  /** Self-close void elements */
  selfClosingVoidElements?: boolean;
  /** Optimize quotes around attribute values */
  quotes?: boolean;
}

interface FragmentOptions extends Options {
  /** HTML parsing mode */
  mode?: "no-quirks" | "limited-quirks" | "quirks";
  /** Context element for fragment parsing */
  context_element?: Element;
  /** Form element context */
  form_element?: Element;
}

Element Types

interface Element {
  /** HTML tag name */
  tagName: string;
  /** Element namespace */
  namespace: string;
  /** Array of element attributes */
  attributes: Array<Attribute>;
  /** Whether element is self-closing */
  isSelfClosing: boolean;
}

interface Attribute {
  /** Optional attribute namespace */
  namespace?: string;
  /** Optional attribute prefix */
  prefix?: string;
  /** Attribute name */
  name: string;
  /** Optional attribute value */
  value?: string;
}

Key Features

The native binary provides these HTML minification capabilities:

  • Whitespace Optimization: Multiple strategies for collapsing whitespace while preserving layout
  • Comment Processing: Remove or preserve comments with pattern matching support
  • Attribute Optimization: Normalize, sort, and remove redundant attributes
  • Boolean Attribute Collapsing: Convert checked="checked" to checked
  • Integrated Content Minification: Minify JavaScript, CSS, and JSON within HTML
  • Tag Omission: Remove optional HTML tags where safe
  • Quote Optimization: Optimize quotes around attribute values
  • Advanced Parsing: Support for different HTML parsing modes and fragment contexts
  • Self-closing Elements: Proper handling of void elements
  • Performance: High-speed processing through Rust implementation

Error Handling

All minification functions return a TransformOutput object that includes:

  • code: The minified HTML string
  • errors: Optional array of Diagnostic objects for warnings or non-fatal errors
const result = await minify(htmlContent);
if (result.errors && result.errors.length > 0) {
  result.errors.forEach(error => {
    console.warn(`${error.level}: ${error.message}`);
  });
}