@vue/language-core
Last updated 2 years ago by johnsoncodehk .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @vue/language-core 
SYNC missed versions from official npm registry.

@vue/language-core

NPM version License

The core module for Vue Language Tools, responsible for parsing Vue Single File Components (SFCs) and transforming them into virtual code structures that TypeScript can understand. This package is a low-level dependency for @vue/language-server and vue-tsc.

Installation

npm install @vue/language-core

Core API

createVueLanguagePlugin

Creates a Vue language plugin for integration with Volar language services.

import { createVueLanguagePlugin } from '@vue/language-core';
import type { LanguagePlugin } from '@volar/language-core';
import ts from 'typescript';

const plugin: LanguagePlugin<string> = createVueLanguagePlugin(
  ts,
  compilerOptions,    // ts.CompilerOptions
  vueCompilerOptions, // VueCompilerOptions
  (scriptId) => scriptId  // asFileName: Converts scriptId to a file name
);

createParsedCommandLine

Parses TypeScript and Vue compiler options from tsconfig.json.

import { createParsedCommandLine } from '@vue/language-core';
import ts from 'typescript';

const parsed = createParsedCommandLine(ts, ts.sys, '/path/to/tsconfig.json');
// parsed.options: ts.CompilerOptions
// parsed.vueOptions: VueCompilerOptions

parse

Parses Vue SFC source code and returns an SFCParseResult.

import { parse } from '@vue/language-core';

const result = parse(`
<template>
  <div>{{ msg }}</div>
</template>
<script setup lang="ts">
const msg = 'Hello'
</script>
`);

// result.descriptor.template
// result.descriptor.scriptSetup
// result.descriptor.styles
// result.errors

vueCompilerOptions

Configure Vue compiler behavior through the vueCompilerOptions field in tsconfig.json:

{
  "compilerOptions": { /* ... */ },
  "vueCompilerOptions": {
    "target": 3.5,
    "strictTemplates": true,
    "plugins": ["@vue/language-plugin-pug"]
  }
}

File Handling Options

Option Type Default Description
target number \| 'auto' 'auto' Vue version. 'auto' reads from node_modules/vue/package.json.
extensions string[] ['.vue'] File extensions to be treated as Vue SFCs.
vitePressExtensions string[] [] File extensions to be treated as VitePress Markdown.
petiteVueExtensions string[] [] File extensions to be treated as Petite Vue HTML.
plugins string[] [] Custom language plugins, e.g., @vue/language-plugin-pug.

Type Checking Options

Option Type Default Description
strictTemplates boolean false A convenience option that enables the four check* options below and strictVModel.
checkUnknownProps boolean false Check for unknown props.
checkUnknownEvents boolean false Check for unknown events.
checkUnknownComponents boolean false Check for unknown components.
checkUnknownDirectives boolean false Check for unknown directives.
strictVModel boolean false Strictly check v-model bindings.
strictCssModules boolean false Strictly check CSS Modules class names (not affected by strictTemplates).

Advanced Options

Option Type Default Description
lib string 'vue' Vue package name, used for generating import statements.
skipTemplateCodegen boolean false Skip virtual code generation for templates.
fallthroughAttributes boolean false Enable type inference for fallthrough attributes.
jsxSlots boolean false Use JSX-style slots types.
dataAttributes string[] [] Allowed data-* attribute patterns.
htmlAttributes string[] ['aria-*'] Allowed HTML attribute patterns.
resolveStyleImports boolean false Resolve import statements in styles.
resolveStyleClassNames boolean \| 'scoped' 'scoped' Resolve class names in styles.

Built-in Plugins

This package includes the following built-in plugins to handle different file types and blocks:

File Parsing Plugins

Plugin Function Controlled By
file-vue Parses .vue files into an SFC structure. extensions
file-md Parses Markdown files into an SFC structure. vitePressExtensions
file-html Parses HTML files into an SFC structure. petiteVueExtensions

Virtual Code Generation Plugins

Plugin Function
vue-tsx Generates TypeScript virtual code from an SFC.
vue-template-html Compiles HTML templates.
vue-template-inline-ts Handles TypeScript expressions in templates.
vue-template-inline-css Handles inline styles in templates.
vue-style-css Compiles CSS styles.
vue-script-js Handles JavaScript script blocks.

Embedded Code Extraction Plugins

Plugin Function
vue-sfc-template Extracts the <template> block.
vue-sfc-styles Extracts <style> blocks.
vue-sfc-scripts Extracts <script> blocks (for formatting).
vue-sfc-customblocks Extracts custom blocks.

Related Packages

License

MIT License

Current Tags

  • 3.1.3                                ...           latest (5 months ago)

119 Versions

  • 3.1.3                                ...           5 months ago
  • 3.1.2                                ...           6 months ago
  • 3.0.10                                ...           6 months ago
  • 3.0.9                                ...           6 months ago
  • 3.1.1                                ...           6 months ago
  • 3.1.0                                ...           6 months ago
  • 3.0.8                                ...           7 months ago
  • 3.1.0-alpha.0                                ...           7 months ago
  • 3.0.7                                ...           7 months ago
  • 3.0.7-alpha.1                                ...           7 months ago
  • 3.0.7-alpha.0                                ...           7 months ago
  • 3.0.6                                ...           8 months ago
  • 3.0.5                                ...           8 months ago
  • 3.0.4                                ...           9 months ago
  • 3.0.3                                ...           9 months ago
  • 3.0.2                                ...           9 months ago
  • 3.0.1                                ...           9 months ago
  • 2.2.12                                ...           9 months ago
  • 3.0.0                                ...           9 months ago
  • 3.0.0-beta.5                                ...           9 months ago
  • 3.0.0-beta.4                                ...           10 months ago
  • 3.0.0-beta.3                                ...           10 months ago
  • 3.0.0-beta.2                                ...           10 months ago
  • 3.0.0-beta.1                                ...           10 months ago
  • 3.0.0-alpha.10                                ...           10 months ago
  • 3.0.0-alpha.8                                ...           a year ago
  • 3.0.0-alpha.6                                ...           a year ago
  • 2.2.10                                ...           a year ago
  • 3.0.0-alpha.4                                ...           a year ago
  • 3.0.0-alpha.2                                ...           a year ago
  • 3.0.0-alpha.0                                ...           a year ago
  • 2.2.8                                ...           a year ago
  • 2.2.6                                ...           a year ago
  • 2.2.4                                ...           a year ago
  • 2.2.2                                ...           a year ago
  • 2.2.0                                ...           a year ago
  • 2.1.10                                ...           a year ago
  • 2.1.8                                ...           a year ago
  • 2.1.6-patch.1                                ...           2 years ago
  • 2.1.6                                ...           2 years ago
  • 2.1.5 [deprecated]           ...           2 years ago
  • 2.1.4                                ...           2 years ago
  • 2.1.2                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.29                                ...           2 years ago
  • 2.0.28                                ...           2 years ago
  • 2.0.26                                ...           2 years ago
  • 2.0.26-alpha.2                                ...           2 years ago
  • 2.0.26-alpha.1                                ...           2 years ago
  • 2.0.26-alpha.0                                ...           2 years ago
  • 2.0.24                                ...           2 years ago
  • 2.0.23-alpha.1                                ...           2 years ago
  • 2.0.23-alpha.0                                ...           2 years ago
  • 2.0.22                                ...           2 years ago
  • 2.0.21                                ...           2 years ago
  • 2.0.20                                ...           2 years ago
  • 2.0.19                                ...           2 years ago
  • 2.0.18                                ...           2 years ago
  • 2.0.17                                ...           2 years ago
  • 2.0.16                                ...           2 years ago
  • 2.0.15                                ...           2 years ago
  • 2.0.14                                ...           2 years ago
  • 2.0.13                                ...           2 years ago
  • 2.0.12                                ...           2 years ago
  • 2.0.11                                ...           2 years ago
  • 2.0.10                                ...           2 years ago
  • 2.0.7                                ...           2 years ago
  • 2.0.6                                ...           2 years ago
  • 2.0.5                                ...           2 years ago
  • 2.0.4                                ...           2 years ago
  • 2.0.3                                ...           2 years ago
  • 2.0.2                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.8.27                                ...           2 years ago
  • 1.8.26                                ...           2 years ago
  • 1.8.25                                ...           2 years ago
  • 1.8.24                                ...           2 years ago
  • 1.9.0-alpha.3                                ...           2 years ago
  • 1.9.0-alpha.2                                ...           2 years ago
  • 1.9.0-alpha.1                                ...           2 years ago
  • 1.9.0-alpha.0                                ...           2 years ago
  • 1.8.22                                ...           2 years ago
  • 1.8.21                                ...           2 years ago
  • 1.8.20                                ...           2 years ago
  • 1.8.19                                ...           3 years ago
  • 1.8.18                                ...           3 years ago
  • 1.8.17                                ...           3 years ago
  • 1.8.16                                ...           3 years ago
  • 1.8.15                                ...           3 years ago
  • 1.8.14                                ...           3 years ago
  • 1.8.13                                ...           3 years ago
  • 1.8.12                                ...           3 years ago
  • 1.8.11                                ...           3 years ago
  • 1.8.10                                ...           3 years ago
  • 1.8.8                                ...           3 years ago
  • 1.8.7                                ...           3 years ago
  • 1.8.6                                ...           3 years ago
  • 1.8.5                                ...           3 years ago
  • 1.8.4                                ...           3 years ago
  • 1.8.3                                ...           3 years ago
  • 1.8.2                                ...           3 years ago
  • 1.8.1                                ...           3 years ago
  • 1.8.0-patch.1                                ...           3 years ago
  • 1.8.0                                ...           3 years ago
  • 1.7.14                                ...           3 years ago
  • 1.7.13                                ...           3 years ago
  • 1.7.12                                ...           3 years ago
  • 1.7.11                                ...           3 years ago
  • 1.7.10                                ...           3 years ago
  • 1.7.9                                ...           3 years ago
  • 1.7.8                                ...           3 years ago
  • 1.7.7                                ...           3 years ago
  • 1.7.6                                ...           3 years ago
  • 1.7.5                                ...           3 years ago
  • 1.7.4                                ...           3 years ago
  • 1.7.3                                ...           3 years ago
  • 1.7.1                                ...           3 years ago
  • 1.7.0                                ...           3 years ago
Downloads
Today 0
This Week 1
This Month 3
Last Day 0
Last Week 2
Last Month 7
Dependencies (8)
Dev Dependencies (5)

Copyright 2013 - present © cnpmjs.org | Home |