PostHTML CLI

raw JSON →
0.10.0 verified Sat Apr 25 auth: no javascript maintenance

Command-line interface for PostHTML, a tool for transforming HTML/XML with plugins. Current stable version is 0.10.0, with releases roughly every few months. It supports processing multiple files, glob patterns, custom config files (JSON/JS), and built-in notifications for updates. Compared to alternatives like html-postcss or custom scripts, posthtml-cli provides a simple CLI with plugin loading and file watching. Requires Node >=10. Currently in maintenance mode with no major recent activity.

error posthtml-cli: command not found
cause posthtml-cli not installed globally or in PATH
fix
Run npm install -g posthtml-cli or use npx posthtml-cli.
error Error: No files matched the given pattern
cause Glob pattern didn't match any files (e.g., missing file extension or wrong path)
fix
Check the pattern: use 'src/**/*.html' for all HTML files in src/
error Error: Cannot find module 'posthtml-load-config'
cause Missing peer dependency posthtml-load-config when using a config file
fix
Install posthtml-load-config: npm install posthtml-load-config --save-dev
breaking v0.9.0: Changed behavior of config loading - now supports async config files
fix If using a config function that returns a promise, ensure compatibility; previously only synchronous was supported.
deprecated v0.8.0: Option --all-in-output replaced with --all-in-out
fix Use --all-in-out instead of --all-in-output.
gotcha Glob patterns on Windows may need escaped or use forward slashes
fix Use forward slashes or double backslashes in glob patterns on Windows.
gotcha Plugin ordering: CLI and config files may combine in unexpected order
fix Check documentation for plugin order precedence (CLI overrides config?).
npm install posthtml-cli
yarn add posthtml-cli
pnpm add posthtml-cli

Install globally, process HTML files with plugins defined in config.

npm install -g posthtml-cli
# Process a single file
echo '<div class="hello">Hi</div>' > input.html
posthtml-cli -i input.html -o output.html
# Process multiple files with a glob
posthtml-cli 'src/**/*.html' -d dist
# Use a config file (.posthtmlrc.js)
echo 'module.exports = { plugins: { "posthtml-include": {} } }' > .posthtmlrc.js
posthtml-cli -i src/index.html -o dist/index.html