highlightjs-vue is a syntax definition plugin for the highlight.js library, specifically designed to provide syntax highlighting for Single-File Components (SFCs) of the Vue.js framework. It enables highlight.js to correctly parse and illuminate the `<template>`, `<script>`, and `<style>` blocks within a `.vue` file by leveraging highlight.js's existing language definitions for HTML, JavaScript/TypeScript, and CSS/SCSS/LESS. The package is currently at version 1.0.0 and appears to be in a maintenance state, with stable functionality but infrequent updates, as its last known update was approximately two years ago. It primarily targets environments where CommonJS modules or global browser scripts are used, without native ESM exports.
npm install highlightjs-vueVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import highlight.js and highlightjs-vue (via CommonJS require), register the 'vue' language definition, and then apply it to a sample Vue Single-File Component (SFC) string. The output is the HTML string with highlighting spans.
For bundlers, ensure `allowSyntheticDefaultImports` or similar configurations are enabled if attempting `import hljsDefineVue from 'highlightjs-vue';`. The safest approach for CJS modules in ESM is often `import * as hljsDefineVueModule from 'highlightjs-vue'; const hljsDefineVue = hljsDefineVueModule.default || hljsDefineVueModule;` if it's a default export, or explicitly `require()` within an async context or a CJS file that exports to ESM.
Ensure the script tags for highlight.js and highlightjs-vue are present, and then call `hljs.registerLanguage("vue", window.hljsDefineVue);` in a subsequent script block.Always load `highlight.js` and ensure its `hljs` object is available before attempting to `require` or register `highlightjs-vue`.
Review the GitHub repository for recent activity or open issues if encountering highlighting inaccuracies with very new Vue syntax. Consider contributing fixes if necessary, or exploring alternative highlighting solutions if active development is a critical requirement.
Ensure `highlight.js` is loaded and its `hljs` object is accessible before calling `hljs.registerLanguage`. If using ESM, `import hljs from 'highlight.js';` is usually correct. For CJS, `const hljs = require('highlight.js');`.Use the CommonJS `require()` syntax: `const hljsDefineVue = require('highlightjs-vue');`. If in an ESM-only file, you might need bundler configuration or a dynamic import (`import('highlightjs-vue').then(m => m.default || m)`) if your environment supports it.Verify that both `<script src="highlightjs">` and `<script src="highlightjs-vue">` tags are correctly placed and loaded *before* the script block that calls `hljs.registerLanguage("vue", window.hljsDefineVue);`.