@vue/language-plugin-pug
v3.2.6
Published
<p> <a href="https://www.npmjs.com/package/@vue/language-plugin-pug"><img src="https://img.shields.io/npm/v/@vue/language-plugin-pug.svg?labelColor=18181B&color=1584FC" alt="NPM version"></a> <a href="https://github.com/vuejs/language-tools/blob/maste
Readme
@vue/language-plugin-pug
A Pug template language plugin for Vue Language Tools, enabling the use of <template lang="pug"> in Vue SFCs.
Installation
npm install @vue/language-plugin-pug --save-devConfiguration
Add this plugin in tsconfig.json:
{
"vueCompilerOptions": {
"plugins": ["@vue/language-plugin-pug"]
}
}Usage
After configuration, you can use Pug syntax in Vue components:
<template lang="pug">
div.container
h1 {{ title }}
p {{ description }}
button(@click="handleClick") Click me
</template>
<script setup lang="ts">
const title = 'Hello'
const description = 'World'
const handleClick = () => console.log('clicked')
</script>Features
This plugin implements the VueLanguagePlugin interface, providing:
getEmbeddedCodes- Identifies<template lang="pug">blocksresolveEmbeddedCode- Extracts Pug content as embedded codecompileSFCTemplate- Compiles Pug to HTML, then parses it into an AST using@vue/compiler-dom
How it Works
- Uses
pug-lexerto convert Pug syntax into tokens - Uses
pug-parserto parse tokens into an AST - Traverses the AST to generate HTML while building a source map
- Uses
@vue/compiler-dom.parseto parse the HTML - Uses
@vue/compiler-dom.transformto transform the AST - Maps error and warning positions back to the original Pug code via the source map
Related Packages
@vue/language-core- Core module
License
MIT License
