Skip to content

[fix]: Using posthtml-cli with postcss autoprefixer #246

@mickeywu

Description

@mickeywu

I'm having problems using the CLI with PostCSS Autoprefixer. I already have posthtml-postcss and autoprefixer packages installed through NPM.

posthtml.json

{
  "posthtml": {
    "postcss": {},
    "plugins": {
      "autoprefixer": {
        "browsers": ["last 2 versions"]
      }
    }
  }
}

Running posthtml -i src/**/*.html -o posthtml/ -c posthtml.json gives me the following error:

(node:17883) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 79): Error: [object Object] is not a PostCSS plugin

After digging into the posthtml-postcss documentation (https://github.com/posthtml/posthtml-postcss), postcss expects a postcssPlugins argument (which is an array) before the usual options argument, as such:

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

What is the proper way (if any) to pass in a list of plugins specifically for PostCSS through the CLI?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions