Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/johnsoncodehk/vite-plugin-vue-component-preview

Vite plugin for preview Vue component
https://github.com/johnsoncodehk/vite-plugin-vue-component-preview

Last synced: about 2 months ago
JSON representation

Vite plugin for preview Vue component

Awesome Lists containing this project

README

        

# vite-plugin-vue-component-preview

This Vite plugin support `` custom block in SFC for preview single Vue component.

To use this with VSCode + Volar, see https://github.com/johnsoncodehk/volar/discussions/1511

## Setup

`vite.config.ts`

```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`

```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)

```json
{
"vueCompilerOptions": {
"plugins": ["vite-plugin-vue-component-preview/tooling"]
}
}
```

## Example

```html

{{ msg }}


count is: {{ count }}

import { ref } from 'vue'

defineProps<{ msg: string }>()

const count = ref(0)

# This is preview page of HelloWorld.vue

## Props

| Props | Description |
| ----------- | -------------- |
| msg | Title message |

## Examples


const msgs = [
'Hello Peter',
'Hello John',
];




body {
background-color: green;
}

```

Example repo: https://github.com/johnsoncodehk/volar-starter (Open http://localhost:3000/__preview/src/components/HelloWorld.vue to see the result.)

### Self-import

When you want to preview the component including ``, importing the component itself provides the solution as follows:

```html




import TestPreview from './TestPreview.vue' // TestPreview.vue is the name of this file itself.
const msgs = ['1', '2']



test {{ msg }}

```

This method relates to [#17](https://github.com/johnsoncodehk/vite-plugin-vue-component-preview/issues/17).

## Sponsors





## Credits

- Markdown parser power by https://github.com/antfu/vite-plugin-vue-markdown