css-surgeon
Takes a single HTML document, removes all unused styles within style-tags and minifies the remains.
The initial intent of this library was to satisfy the size limits of CSS within AMP pages.
Therefore no CSS within an <style amp-boilerplate>
-tag will be touched.
Installation
yarn add css-surgeon
Usage
Just pass the HTML document to the exposed operate
-function.
The function returns a promise which resolves with the whole document.
; const htmlWithMinifiedCss = await ;
Example
Take this HTML document for example. There are several unused rules and selectors.
single style-tag used element
The result of the operate
-function will be:
single style-tag used element
Note: The strange formatting is the result of
JSDOM.serialize()
.
Tests
$ yarn install$ yarn test