# @winner-fed/unplugin-vue-setup-extend

> Extending the vue script setup syntactic sugar

Latest version **0.0.3** (published 2022-03-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @winner-fed/unplugin-vue-setup-extend
pnpm add @winner-fed/unplugin-vue-setup-extend
yarn add @winner-fed/unplugin-vue-setup-extend
bun add @winner-fed/unplugin-vue-setup-extend
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2022-03-14 |
| First published | 2022-03-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 15.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | winner-fed |
| Keywords | unplugin, vue3, script, setup, name |

## Links

- npm: https://www.npmjs.com/package/@winner-fed/unplugin-vue-setup-extend
- Repository: https://github.com/cklwblove/unplugin-vue-setup-extend
- Homepage: https://github.com/cklwblove/unplugin-vue-setup-extend#readme
- Issues: https://github.com/cklwblove/unplugin-vue-setup-extend/issues
- npm.io page: https://npm.io/package/@winner-fed/unplugin-vue-setup-extend

## Dependencies (3)

- [unplugin](https://npm.io/package/unplugin.md) ^0.2.7
- [magic-string](https://npm.io/package/magic-string.md) ^0.25.7
- [@vue/compiler-sfc](https://npm.io/package/@vue/compiler-sfc.md) ^3.2.29

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 0.0.3 (latest) — 2022-03-14
- 0.0.2 — 2022-03-14
- 0.0.1 — 2022-03-14

## README

# unplugin-vue-setup-extend

[![NPM version](https://img.shields.io/npm/v/@winner-fed/unplugin-vue-setup-extend?color=a1b858&label=)](https://www.npmjs.com/package/@winner-fed/unplugin-vue-setup-extend)

Support `<script name>` for Vue script setup.

## Install

**node version:** >=12.0.0

**vite version:** >=2.0.0

```bash
npm i unplugin-vue-setup-extend -D
# or
yarn add unplugin-vue-setup-extend -D
```

<details>
<summary>Vite</summary><br>

```ts
// vite.config.ts
import vueSetupExtend from '@winner-fed/unplugin-vue-setup-extend/vite'

export default defineConfig({
  plugins: [
    vueSetupExtend({ /* options */ }),
  ],
})
```

Example: [`playground/`](./playground/)

<br></details>

<details>
<summary>Rollup</summary><br>

```ts
// rollup.config.js
import vueSetupExtend from '@winner-fed/unplugin-vue-setup-extend/rollup'

export default {
  plugins: [
    vueSetupExtend({ /* options */ }),
  ],
}
```

<br></details>


<details>
<summary>Webpack</summary><br>

```ts
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('@winner-fed/unplugin-vue-setup-extend/webpack').default({ /* options */ })
  ]
}
```

<br></details>

<details>
<summary>Nuxt</summary><br>

```ts
// nuxt.config.js
export default {
  buildModules: [
    ['@winner-fed/unplugin-vue-setup-extend/nuxt', { /* options */ }],
  ],
}
```

> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)

<br></details>

<details>
<summary>Vue CLI</summary><br>

```ts
// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require('@winner-fed/unplugin-vue-setup-extend/webpack').default({ /* options */ }),
    ],
  },
}
```

<br></details>
 
## Note
当 `script` 标签里不存在任何代码时，`@vue/compiler-sfc` 转换后的 `scriptSetup` 为 `null`，此种情况不支持转换。

```javascript
 const { parse, compileScript } = require("@vue/compiler-sfc");

const { descriptor } = parse(
`
<template><h1>12312312</h1></template>
<script setup name="App"></script>
`
);

console.log(descriptor);

```

`descriptor` 转换后的结果如下：

```javascript
{
  filename: 'anonymous.vue',
  source: '\n' +
    '  <template><h1>12312312</h1></template><script setup name="App"></script>\n',
  template: {
    type: 'template',
    content: '<h1>12312312</h1>',
    loc: { source: '<h1>12312312</h1>', start: [Object], end: [Object] },
    attrs: {},
    ast: {
      type: 1,
      ns: 0,
      tag: 'template',
      tagType: 0,
      props: [],
      isSelfClosing: false,
      children: [Array],
      loc: [Object],
      codegenNode: undefined
    },
    map: {
      version: 3,
      sources: [Array],
      names: [],
      mappings: 'AACA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC',
      file: 'anonymous.vue',
      sourceRoot: '',
      sourcesContent: [Array]
    }
  },
  script: null,
  scriptSetup: null,
  styles: [],
  customBlocks: [],
  cssVars: [],
  slotted: false,
  shouldForceReload: [Function: shouldForceReload]
}
```

---
_Source: https://npm.io/package/@winner-fed/unplugin-vue-setup-extend · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
