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

https://github.com/mattjennings/vite-plugin-sveld

A vite plugin to parse your Svelte components through sveld
https://github.com/mattjennings/vite-plugin-sveld

Last synced: 2 months ago
JSON representation

A vite plugin to parse your Svelte components through sveld

Awesome Lists containing this project

README

        

# vite-plugin-sveld

A vite plugin to parse your Svelte components through [sveld](https://github.com/IBM/sveld)

## Setup

```
npm install -D vite-plugin-sveld sveld
```

```js
// vite.config.js
import sveld from 'vite-plugin-sveld'

export default {
plugins: [sveld()]
...
}
```

## Usage

By adding `?raw&sveld` to a .svelte import, it will return the JSON output from sveld for that component.

```svelte

import docs from './Button.svelte?raw&sveld'



Name
Type
Default
Description



{#each docs.props as prop}

{prop.name}
{prop.type?.replace(/'/g, '"')}
{prop.value?.replace(/'/g, '"') ?? ''}
{@html prop.description ? prop.description : ''}

{/each}

```

## ?raw&sveld types

If you'd like to have the sveld imports typed, add

```
///
```

to a `src/global.d.ts` file or similar in your project. Imports _must_ have `?raw&sveld` specifically to be typed. Adding additional query params, or flipping to `?sveld&raw` will cause them to be untyped.