/posthtml-style-to-file

Save DOM styles to CSS file

Primary LanguageJavaScriptMIT LicenseMIT

NPM Deps Tests Coverage

Style-to-File Plugin

Save DOM styles to CSS file

Install

npm i -D posthtml-style-to-file

Usage

Options

path

Type: String
Default: ./result.css
Description: Destination path, where the extracted CSS is saved to.

removeStyle

Type: String
Default: ``
Description: Removes the specified value attrs | `tag` | `all`

removeStyle

Destination path, where the extracted CSS is saved to.

Example

const posthtml = require('posthtml')
const styleToFile = require('posthtml-style-to-file')

const html = readFileSync('path/to/html', 'utf8')

posthtml([ styleToFile({ path: './dist/style.css' }) ])
    .process(html)
    .then((result) => console.log(result.html))

index.html

<html>
<head>
    <title>Wow</title>
    <style type="text/css">
        html { margin: 0 }
    </style>
</head>
<body style="background: #fff;">
  <div class="button" style="border: 1px solid #000;">
    <div class="button__text">
        Text
    </div>
  </div>
</body>
</html>

style.css

html{ margin: 0 }
body{ background: #fff; }
div.button{ border: 1px solid #000; }