vite-plugin-vue-options
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

vite-plugin-vue-options

A compile macro to make the usage of options api in setup script with ease.

NPM version

Get started

pnpm i vite-plugin-vue-options

Usage

  1. Setup plugin in vite.config.ts
import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
import VueOptions from 'vite-plugin-vue-options'

export default defineConfig({
  plugins: [Vue(), VueOptions()],
})
  1. Usage in vue SFC
<template>
  <div>
    foo
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

defineOptions({
  name: 'FooBar',
})

const foo = ref('foo')
</script>

Using defineOptions fn to set option api in setup script.

The above code will be compiled into:

<script lang="ts">
export default {
  name: 'FooBar',
}
</script>

<template>
  <div>
    foo
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const foo = ref('foo')
</script>
  1. Typescript support (Optional)
{
  "types": [
    "vite-plugin-vue-options"
  ]
}

Then you can use defineOptions with type emits.

Caveats

Currently, the plugin only supports the defineOptions function in the setup script, and can not access outer variables.

License

MIT License © 2022 guygubaby

Readme

Keywords

none

Package Sidebar

Install

npm i vite-plugin-vue-options

Weekly Downloads

2

Version

0.1.4

License

MIT

Unpacked Size

13.2 kB

Total Files

7

Last publish

Collaborators

  • guygubaby