Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sondr3/astro-html-minifier
DEPRECATED: A HTML minifier for Astro
https://github.com/sondr3/astro-html-minifier
astro astro-component
Last synced: 2 months ago
JSON representation
DEPRECATED: A HTML minifier for Astro
- Host: GitHub
- URL: https://github.com/sondr3/astro-html-minifier
- Owner: sondr3
- License: mit
- Created: 2022-08-27T18:25:16.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-08T11:55:04.000Z (9 months ago)
- Last Synced: 2024-07-31T22:39:29.880Z (6 months ago)
- Topics: astro, astro-component
- Language: TypeScript
- Homepage:
- Size: 158 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- my-awesome-astro - astro-html-minifier - HTML minifier for Astro (What Do I Use... / If I want to minify my website?)
README
astro-html-minifier
A HTML minifier for Astro**DEPRECATED: You don't need this anymore!**
Since [Astro 2.5](https://astro.build/blog/astro-250/#html-minification) 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 bundlesTable of Contents
## Table of Contents
- [Quickstart](#quickstart)
- [Usage](#usage)
- [Configuration](#configuration)
- [License](#license)# Quickstart
Install via your tool of choice:
```sh
# 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:```js
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:```js
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 `` and `` 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 `` 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.