A Vite plugin that provides a virtual module for PrismJS, enabling on-demand loading of languages, plugins, and themes with tree-shaking. Current stable version is 1.1.1. Supports Vite 5, 6, 7, and 8. Ships TypeScript declarations. Key differentiator: integrates seamlessly with Vite's virtual module system, allowing bundlers to tree-shake unused parts of PrismJS, reducing bundle size. Compared to alternatives like manual PrismJS setup or other plugins, this offers a declarative config-driven approach with built-in CSS handling and first-class TypeScript support.
npm install vite-plugin-prismjs-plusVerified import paths — ran on the pinned version, not inferred.
Configures the plugin to include PrismJS with specified languages, plugins, and theme, then imports the virtual module and applies highlighting to all code blocks.
Use import Prism from 'virtual:prismjs' in your application code.
Use ES module import syntax: import prismjsPlugin from 'vite-plugin-prismjs-plus'.
Set css: true in plugin options to include theme CSS, or manually import CSS files.
Ensure the theme file exists at the expected path, e.g., 'my-pkg/themes/prism-ocean.css' for 'my-pkg/ocean'.
Ensure no other plugin uses the 'virtual:prismjs' module ID. This plugin does not allow customization of the ID.
Add /// <reference types="vite-plugin-prismjs-plus/client" /> to a declaration file (e.g., vite-env.d.ts).
Change require('vite-plugin-prismjs-plus') to import prismjsPlugin from 'vite-plugin-prismjs-plus'.Verify the plugin is included in vite.config.js. The virtual module should be imported as import Prism from 'virtual:prismjs'.
Call Prism.highlightAll() after DOM content is loaded (e.g., in a DOMContentLoaded event listener).