{"id":22780,"library":"vite-plugin-posthtml","title":"Vite Plugin PostHTML","description":"Vite plugin to run PostHTML transformations on served/built HTML files (index.html). Current version is 0.0.3. It supports mixing synchronous and asynchronous PostHTML plugins, runs in asynchronous mode, and allows overriding the PostHTML function. Compared to other PostHTML integrations, this plugin is specifically designed for Vite's plugin system and processes the HTML entry point.","status":"active","version":"0.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/chromeos/static-site-scaffold-modules","tags":["javascript","vite-plugin","posthtml"],"install":[{"cmd":"npm install vite-plugin-posthtml","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-posthtml","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-posthtml","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for PostHTML transformations","package":"posthtml","optional":false}],"imports":[{"note":"ESM-only; named export, not default.","wrong":"import posthtmlPlugin from 'vite-plugin-posthtml'","symbol":"posthtmlPlugin","correct":"import { posthtmlPlugin } from 'vite-plugin-posthtml'"},{"note":"CommonJS require with destructuring.","wrong":"const posthtmlPlugin = require('vite-plugin-posthtml')","symbol":"posthtmlPlugin (CommonJS)","correct":"const { posthtmlPlugin } = require('vite-plugin-posthtml')"},{"note":"TypeScript type import; config interface not exported as value.","wrong":"import { PostHTMLPluginConfig } from 'vite-plugin-posthtml'","symbol":"(none)","correct":"import type { PostHTMLPluginConfig } from 'vite-plugin-posthtml'"}],"quickstart":{"code":"// vite.config.js\nimport { defineConfig } from 'vite';\nimport { posthtmlPlugin } from 'vite-plugin-posthtml';\n// Optionally import PostHTML plugins\nimport include from 'posthtml-include';\n\nexport default defineConfig({\n  plugins: [\n    posthtmlPlugin({\n      plugins: [include({ root: './src' })],\n      options: { /* parser options, sync: false forced */ },\n    }),\n  ],\n});\n","lang":"javascript","description":"Sets up Vite with posthtmlPlugin including a PostHTML plugin, demonstrating configuration and import."},"warnings":[{"fix":"Use additional handling if you need to process multiple HTML files.","message":"Plugin runs only on the main HTML entry (index.html), not on other HTML files","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Do not rely on sync mode; plugins must work asynchronously.","message":"The sync option in options is always overridden to false (async mode)","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Check compatibility with your Vite version (likely 2.x or 3.x).","message":"Version 0.0.3 may have limited support for newer Vite versions","severity":"deprecated","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use import { posthtmlPlugin } from 'vite-plugin-posthtml'","cause":"Default import instead of named import","error":"TypeError: posthtmlPlugin is not a function"},{"fix":"Install the peer dependency: npm install posthtml","cause":"Missing peer dependency posthtml","error":"Error: Cannot find module 'posthtml'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}