
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
vite-plugin-vue-component-preview
Advanced tools
This Vite plugin support `` custom block in SFC for preview single Vue component.
This Vite plugin support <preview lang="md">
custom block in SFC for preview single Vue component.
To use this with VSCode + Volar, see https://github.com/johnsoncodehk/volar/discussions/1511
vite.config.ts
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import preview from 'vite-plugin-vue-component-preview';
export default defineConfig({
plugins: [
preview(),
vue(),
],
})
main.ts
import { createApp } from 'vue';
import App from './App.vue';
import Preview from 'vite-plugin-vue-component-preview/client';
const app = createApp(App);
app.use(Preview);
tsconfig.json
(For IDE and vue-tsc support)
{
"vueCompilerOptions": {
"plugins": ["vite-plugin-vue-component-preview/tooling"]
}
}
<!-- Component part -->
<template>
<h1>{{ msg }}</h1>
<button @click="count++">count is: {{ count }}</button>
</template>
<script setup lang="ts">
import { ref } from 'vue'
defineProps<{ msg: string }>()
const count = ref(0)
</script>
<!-- Preview part -->
<preview lang="md">
# This is preview page of HelloWorld.vue
## Props
| Props | Description |
| ----------- | -------------- |
| msg | Title message |
## Examples
<script setup>
const msgs = [
'Hello Peter',
'Hello John',
];
</script>
<template v-for="msg in msgs">
<slot :msg="msg"></slot>
</template>
<style>
body {
background-color: green;
}
</style>
</preview>
Example repo: https://github.com/johnsoncodehk/volar-starter (Open http://localhost:3000/__preview/src/components/HelloWorld.vue to see the result.)
When you want to preview the component including <slot>
, importing the component itself provides the solution as follows:
<template>
<div>
<slot></slot>
</div>
</template>
<preview lang="md">
<script setup>
import TestPreview from './TestPreview.vue' // TestPreview.vue is the name of this file itself.
const msgs = ['1', '2']
</script>
<template v-for="msg in msgs">
<TestPreview>
test {{ msg }}
</TestPreview>
</template>
</preview>
This method relates to #17.
FAQs
This Vite plugin support `` custom block in SFC for preview single Vue component.
The npm package vite-plugin-vue-component-preview receives a total of 511 weekly downloads. As such, vite-plugin-vue-component-preview popularity was classified as not popular.
We found that vite-plugin-vue-component-preview demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.