Vue Parser is a utility library designed to parse the contents of Vue Single File Components (.vue files) by leveraging an Abstract Syntax Tree (AST), specifically based on the `parse5` library. It enables developers to extract specific content from `<template>`, `<script>`, or `<style>` tags. A key differentiator is its ability to pad the extracted content with a specified string (defaulting to comments for script/style) to preserve original line numbers, which is particularly beneficial for linting and error reporting tools. The current stable version is 1.1.6, but the package has not seen updates for approximately four years as of April 2026. This lack of recent development suggests the project is abandoned, which may lead to compatibility issues with newer versions of Vue.js (especially Vue 3+), Node.js, or related ecosystem tools.
npm install vue-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing a Vue SFC to extract content from `<script>`, `<template>`, and `<style>` tags, illustrating how to specify language attributes and showing the resulting padded output for preserving line numbers.
For new projects or existing ones targeting Vue 3+, consider using actively maintained alternatives like `@vue/compiler-sfc` or `vue-eslint-parser` which are designed for modern Vue ecosystems.
To remove padding, you will need to manually strip the leading padding characters after extraction. The documentation mentions a `padding` option for customization, but its exact usage for disabling or specific string configuration needs to be verified.
Manually inspect the output for complex Vue components. For robust parsing of modern Vue SFCs, specialized tools like `@vue/compiler-sfc` are recommended as they are integrated with the Vue core.
Ensure you are using `import vueParser from 'vue-parser'` for ESM or `const vueParser = require('vue-parser')` for CommonJS to correctly access the default exported function.Run `npm install vue-parser` or `yarn add vue-parser` to ensure the package is installed and accessible to your project.
Verify the `lang` attribute in your Vue file's tag (e.g., `<script lang="ts">`) and ensure it's included in the `lang` array option passed to `parse`. For instance, `{ lang: ['ts', 'js'] }` would match both TypeScript and JavaScript scripts.