rehype-preset-minify

rehype preset to minify and mangle HTML

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
rehype-preset-minify
6.0.0a year ago6 years agoMinified + gzip package size for rehype-preset-minify in KB

Readme

rehype-preset-minify
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sizesize-badgesize !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
rehyperehype preset to minify HTML.
In
<!doctype html>
<html lang="en-GB">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="content-language" content="en-US">
    <script src="index.js" type="text/javascript" language="javascript">
      alert(true);
    </script>
    <link rel="stylesheet" href="index.css" type="text/css">
    <title>Foo  &  bar</title>
  </head>
  <body>
    <h1 class="foo foo">bar  bar</h1>
    <p id="alfred" id="alfred">  <strong>foo</strong> <em>bar</em> </p>
    <button type="BUTTON" onclick="javascript:return false">Alpha</button>
  </body>
</html>
Out
<!doctypehtml><html lang=en-US><meta charset=utf8><script src=index.js></script><link rel=stylesheet href=index.css><title>Foo & bar</title><h1 class=foo>bar bar</h1><p id=alfred><strong>foo</strong> <em>bar</em></p><button type=button onclick=return!1>Alpha</button>

Install

This package is ESM onlyesm: Node 12+ is needed to use it and it must be importeded instead of requiredd.
npm install rehype-preset-minify
This package exports no identifiers.
The default export is `rehypePresetMinify`

## CLI

After installing, add the following to `.rehyperc` (or `package.json` under
`"rehype"`):

```js
{
  "plugins": [
    "preset-minify"
  ]
}

Then use rehype-clicli:
rehype src/ --output dist/

API

Use:
import {rehype} from 'rehype'
import rehypePresetMinify from 'rehype-preset-minify'

const doc = `<!doctype html>
<html>
  <head>
    <title>Hello</title>
  </head>
  <body>
    <h1>World!</h1>
  </body>
</html>
`

rehype()
  .use(rehypePresetMinify)
  .process(doc)
  .then((file) => {
    console.log(String(file))
  })

Yields:
<!doctypehtml><title>Hello</title><h1>World!</h1>

Contribute

See contributing.mdcontributing in rehypejs/.githubhealth for ways to get started. See support.mdsupport for ways to get help.
This project has a code of conductcoc. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MITlicense © Titus Wormerauthor