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

https://github.com/cyansalt/vue-spinach

Transform Vue SFC between Option API and Composition API
https://github.com/cyansalt/vue-spinach

composition-api vue

Last synced: 5 months ago
JSON representation

Transform Vue SFC between Option API and Composition API

Awesome Lists containing this project

README

          

# vue-spinach

[![npm](https://img.shields.io/npm/v/vue-spinach.svg)](https://www.npmjs.com/package/vue-spinach)

> Popeye can save Olive with the power of spinach. So do Olive.

Transform Vue SFC between Option API and Composition API.

> [!NOTE]
> This is **NOT** an official library of Vue.

> [!TIP]
> Currently only the transformation from Option API to Composition API is supported.

## Usage

### CLI

```shell
pnpm dlx vue-spinach [--print] [--out outFile] [--config configFile]
```

vue-spinach will read the file contents from `process.stdin` if `inFile` is not specified.

`outFile` defaults to the same as `inFile`, unless `inFile` is not specified or `print` is specified. Then it will be output via `process.stdout`.

`configFile` specifies an ES Module file with default exports. Refer to [Options](#options).

### JS API

```ts
import type { TransformOptions } from 'vue-spinach'
import { transformSFC } from 'vue-spinach'

function transformSFC(code: string, userOptions?: Partial): string
```

```js
import { transformSFC } from 'vue-spinach'

const code = transformSFC(`

export default {
// ...
}

`, {
reactivityTransform: true,
})
```

### Options

```ts
interface TransformOptions {
/**
* Always generate code in typescript
* @default false
*/
typescript: boolean,
/**
* Whether to generate block.
* @default true
*/
scriptSetup: boolean,
/**
* Whether to generate code using [Reactivity Transform]{@link https://vue-macros.dev/features/reactivity-transform.html}.
* @default false
*/
reactivityTransform: boolean,
/**
* Whether to destructure props defined by `defineProps`.
* Only valid when `scriptSetup` is `true`.
* @default true
*/
propsDestructure: boolean,
/**
* Specifies a mapping of import names.
* For example `{ 'vue-router': 'vue-router-v4' }`.
* @default {}
*/
aliases: Record<string, string>,
/**
* Specifies additional plugins.
* Plugins that transform Vue's built-in options are always enabled.
* @default [...builtinPlugins]
*/
plugins: Plugin[],
}
```

### Plugin

See [Write a Plugin](/docs/write-a-plugin.md).