vue-prism-component is a Vue component wrapper for Prism.js, providing syntax highlighting capabilities within Vue applications. The current stable version is 2.0.0, which targets Vue 3. Version 1.x supports Vue 2. The package maintains a steady release cadence, with updates typically driven by new Vue major versions or dependency updates. Its key differentiator is its straightforward integration into Vue SFCs and JSX, allowing developers to easily display formatted code blocks or inline code snippets using the popular Prism.js library. Unlike direct Prism.js usage, this component handles reactivity and rendering within the Vue ecosystem, simplifying dynamic code display and theme management. It requires `prismjs` as a peer dependency for core highlighting functionality and themes.
npm install vue-prism-componentVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up and use `vue-prism-component` in a Vue 3 application. It shows importing Prism.js core, a theme, and specific language components, then renders both block and inline code snippets using the `<Prism>` component with `language` and `code` props.
If migrating to Vue 3, update `vue-prism-component` to v2.0.0. For Vue 2 projects, ensure `vue-prism-component` is pinned to a version less than 2.0.0 (e.g., `^1.0.0`).
Run `npm install prismjs` or `yarn add prismjs`. Then, in your main app file or a relevant component, add `import 'prismjs'` and `import 'prismjs/themes/prism.css'` (or your chosen theme).
For each specific language you wish to highlight, add an import like `import 'prismjs/components/prism-python'` to your application's entry point or relevant component.
Ensure `Prism` is imported and registered in the `components` option of your Vue component (e.g., `components: { Prism }`) or globally registered if using `app.component()`.Install `prismjs` by running `npm install prismjs` or `yarn add prismjs`. Verify that your package manager successfully installed it.
In your main application entry point (e.g., `main.js`/`main.ts`), add `import 'prismjs'` and `import 'prismjs/themes/prism.css'` (or the path to your preferred theme).