Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rehype-remove-unused-css

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-remove-unused-css

Rehype plugin to remove unused stylesheet with uncss

  • 0.1.4
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Rehype remove unused css

Rehype plugin to remove unused stylesheet with uncss

Installation

npm install rehype-remove-unused-css

Usage

Say example.html looks as follows;

<html>
    <head>
        <style>
            .one {
                font-size: 1em;
            }
            .two {
                font-size: 2em;
            }
        </style>
    </head>
    <body>
        <p class="one">example</p>
    </body>
</html>

...and example.js like this:

const vfile = require("to-vfile")
const report = require("vfile-report")
const unified = require("unified")
const rehype = require("rehype-parse")
const stringify = require("rehype-stringify")
const removeUnusedCss = require("rehype-remove-unused-css")

unified()
    .use(rehype)
    .use(removeUnusedCss)
    .use(stringify)
    .processSync(vfile.readSync("example.html"), (err, file) => {
        console.error(report(err || file))
        console.log(String(file))
    })

Now, running node example yields:

<html>
    <head>
        <style>
            .one {
                font-size: 1em;
            }
        </style>
    </head>
    <body>
        <p class="one">example</p>
    </body>
</html>

API

rehype().use(removeUnusedCss[, options])

Remove unused stylesheet.

  • options is same as options of uncss

Security

Use of rehype-remove-unused-css should be safe to use as JSDOM should be safe to use. When in doubt, use rehype-sanitize.

License

MIT © TANIGUCHI Masaya

Keywords

FAQs

Package last updated on 05 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc