Skip to content

Commit

Permalink
chore: update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
cossssmin committed Feb 26, 2024
1 parent 83d2e69 commit 8f62b2d
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,28 @@ npm i -D posthtml-postcss
## Usage

```js
const { readFileSync } = require('fs')
import {dirname} from 'node:path'
import {readFileSync} from 'node:fs'
import {fileURLToPath} from 'node:url'

const posthtml = require('posthtml')
const postcss = require('posthtml-postcss')
import posthtml from 'posthtml'
import postcss from 'posthtml-postcss'

const postcssPlugins = []
const postcssOptions = {}
const filterType = /^text\/css$/

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

const filePath = `${__dirname}/index.html`
const html = readFileSync(filePath, 'utf8')

posthtml([ postcss(postcssPlugins, postcssOptions, filterType) ])
.process(html, { from: filePath })
.then((result) => console.log(result.html))
posthtml([
postcss(postcssPlugins, postcssOptions, filterType)
])
.process(html, {from: filePath})
.then((result) => console.log(result.html))
```
If you don't pass any arguments to `posthtml-postcss`, it will try to use your project's PostCSS configuration (see [`postcss-load-config`](https://www.npmjs.com/package/postcss-load-config)).
Expand All @@ -42,11 +49,12 @@ Notice that we're setting the option `from` when calling `process`. `posthtml-po
## Example
```js
const posthtml = require('posthtml')
const postcss = require('posthtml-postcss')
import posthtml from 'posthtml'
import postcss from 'posthtml-postcss'
import autoprefixer from 'autoprefixer'

const postcssPlugins = [
require('autoprefixer')({ browsers: ['last 2 versions'] })
autoprefixer({ browsers: ['last 2 versions'] })
]
const postcssOptions = {}
const filterType = /^text\/css$/
Expand All @@ -56,9 +64,11 @@ const html = `
<div style="display: flex;">Text</div>
`

posthtml([ postcss(postcssPlugins, postcssOptions, filterType) ])
.process(html)
.then((result) => console.log(result.html))
posthtml([
postcss(postcssPlugins, postcssOptions, filterType)
])
.process(html)
.then(result => console.log(result.html))
```
Output:
Expand Down

0 comments on commit 8f62b2d

Please sign in to comment.