开发者社区> 镜像站> NPM> rehype-preset-minify
rehype-preset-minify
Preset to minify and mangle HTML with rehype
Last updated 4 years ago by wooorm .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install rehype-preset-minify 
SYNC missed versions from official npm registry.

rehype-preset-minify

Build Coverage Downloads Size Sponsors Backers Chat

rehype 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  &amp;  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 &amp 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

npm:

npm install rehype-preset-minify

CLI

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

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

Then use rehype-cli:

rehype src -o dist

API

Use:

var rehype = require('rehype')
var minify = require('rehype-preset-minify')

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

rehype()
  .use(minify)
  .process(doc, function(err, file) {
    if (err) throw err
    console.log(String(file))
  })

Yields:

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

Contribute

See contributing.md in rehypejs/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

Current Tags

  • 5.1.0                                ...           latest (a month ago)

12 Versions

  • 5.1.0                                ...           a month ago
  • 5.0.3                                ...           5 months ago
  • 5.0.2                                ...           6 months ago
  • 5.0.1                                ...           8 months ago
  • 5.0.0                                ...           8 months ago
  • 4.0.0                                ...           a year ago
  • 3.0.2                                ...           a year ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.0                                ...           4 years ago
  • 1.0.0                                ...           4 years ago