This package has been deprecated

Author message:

Astro has this feature built-in since version 2.5

astro-html-minifier
TypeScript icon, indicating that this package has built-in type declarations

0.5.1 • Public • Published

astro-html-minifier

GitHub Actions Status npm version

A HTML minifier for Astro

DEPRECATED: You don't need this anymore!

Since Astro 2.5 HTML minification is built in.

  • Simple: Set it and forget it
  • Performant: Uses highly performant libraries to minify
  • Optimal: By minifying, the server can serve optimal bundles
Table of Contents

Table of Contents

Quickstart

Install via your tool of choice:

# Using NPM
npm run astro add astro-html-minifier
# Using Yarn
yarn astro add astro-html-minifier
# Using PNPM
pnpm astro add astro-html-minifier

Then, restart the dev server by typing CTRL-C and then npm run dev in the terminal window that was running Astro.

Usage

First, install the package with your favorite package manager: pnpm add --dev astro-html-minifier, then configure it in your astro.config.* file in the integrations property:

import { defineConfig } from "astro/config";
import minifyHtml from "astro-html-minifier";

export default defineConfig({
  // ...
  integrations: [minifyHtml()],
});

Configuration

While the default options should serve most users well, you may want to change the options yourself. The options are as follows:

export interface HTMLOptions {
  /** Do not minify DOCTYPEs. Minified DOCTYPEs may not be spec compliant. */
  doNotMinifyDoctype?: boolean; // true
  /** Ensure all unquoted attribute values in the output do not contain any characters prohibited by the WHATWG specification. */
  ensureSpecCompliantUnquotedAttributeValues?: boolean; // true
  /** Do not omit closing tags when possible. */
  keepClosingTags?: boolean; // true
  /** Do not omit `<html>` and `<head>` opening tags when they don't have attributes. */
  keepHtmlAndHeadOpeningTags?: boolean; // true
  /** Keep spaces between attributes when possible to conform to HTML standards. */
  keepSpacesBetweenAttributes?: boolean; // true
  /** Keep all comments. */
  keepComments?: boolean; // false
  /**
   * If enabled, content in `<script>` tags with a JS or no [MIME type](https://mimesniff.spec.whatwg.org/#javascript-mime-type) will be minified using [minify-js](https://github.com/wilsonzlin/minify-js).
   */
  minifyJs?: boolean; // true
  /**
   * If enabled, CSS in `<style>` tags and `style` attributes will be minified.
   */
  minifyCss?: boolean; // true
  /** Remove all bangs. */
  removeBangs?: boolean; // false
  /** Remove all processing_instructions. */
  removeProcessingInstructions?: boolean; // false
}

import { defineConfig } from "astro/config";
import minifyHtml from "astro-html-minifier";

export default defineConfig({
  // ...
  integrations: [minifyHtml({ keepComments: true, minifyJs: false })],
});

License

MIT.

Package Sidebar

Install

npm i astro-html-minifier

Weekly Downloads

27

Version

0.5.1

License

MIT

Unpacked Size

24.1 kB

Total Files

21

Last publish

Collaborators

  • sondr3