0.5.1 • Published 8 months ago

astro-html-minifier v0.5.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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

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.

0.5.1

8 months ago

0.5.0

11 months ago

0.3.0

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.2.0

2 years ago

0.1.0

2 years ago