Socket
Socket
Sign inDemoInstall

posthtml-postcss

Package Overview
Dependencies
2
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    posthtml-postcss

Use PostCSS with PostHTML


Version published
Weekly downloads
692
increased by11.79%
Maintainers
3
Install size
1.03 MB
Created
Weekly downloads
 

Changelog

Source

1.0.0 (2024-02-26)

  • chore: update changelog.md (f51ed5d)
  • chore: update readme.md (8f62b2d)
  • ci: update node versions in github workflow (4f350b1)
  • refactor: to esm (74b3363)

Readme

Source
PostHTML

PostCSS Plugin

Use PostCSS with PostHTML

Version Build License Downloads

Install

npm i -D posthtml-postcss

Usage

import {dirname} from 'node:path'
import {readFileSync} from 'node:fs'
import {fileURLToPath} from 'node:url'

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))

If you don't pass any arguments to posthtml-postcss, it will try to use your project's PostCSS configuration (see postcss-load-config).

Notice that we're setting the option from when calling process. posthtml-postcss forwards this to PostCSS, which is useful for syntax error messages. (postcss-cli and gulp-posthtml are setting from automatically.)

Example

import posthtml from 'posthtml'
import postcss from 'posthtml-postcss'
import autoprefixer from 'autoprefixer'

const postcssPlugins = [
  autoprefixer({ browsers: ['last 2 versions'] })
]
const postcssOptions = {}
const filterType = /^text\/css$/

const html = `
  <style>div { display: flex; }</style>
  <div style="display: flex;">Text</div>
`

posthtml([ 
  postcss(postcssPlugins, postcssOptions, filterType) 
])
  .process(html)
  .then(result => console.log(result.html))

Output:

<style>
  div { display: -webkit-flex;display: -ms-flexbox;display: flex; }
</style>
<div style="display: -webkit-flex;display: -ms-flexbox;display: flex;">
  Text
</div>

Keywords

FAQs

Last updated on 26 Feb 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc