Skip to content

feat(better-define): init #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/gorgeous-monkeys-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@vue-macros/common': minor
'unplugin-vue-macros': minor
'@vue-macros/api': patch
'@vue-macros/better-define': patch
'@vue-macros/hoist-static': patch
'@vue-macros/short-emits': patch
---

add better define
4 changes: 4 additions & 0 deletions docs/.vitepress/configs/navs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export const sidebar: DefaultTheme.Sidebar = [
text: 'namedTemplate',
link: '/features/named-template',
},
{
text: 'betterDefine',
link: '/features/better-define',
},
],
},
]
42 changes: 42 additions & 0 deletions docs/features/better-define.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# betterDefine

With enabling `betterDefine`, imported types is supported in `<script setup>` type-based-macros.

[Related issue](https://github.com/vuejs/core/issues/4294)

| Features | Supported |
| :----------------: | :----------------: |
| Vue 3 | :white_check_mark: |
| Vue 2 | :white_check_mark: |
| TypeScript / Volar | :white_check_mark: |

## Basic Usage

:::: code-group

::: code-group-item App.vue

```vue
<script setup lang="ts">
import type { BaseProps } from './types'

interface Props extends BaseProps {
foo: string
}
defineProps<Props>()
</script>
```

:::

::: code-group-item types.ts

```ts
export interface BaseProps {
title: string
}
```

:::

::::
6 changes: 6 additions & 0 deletions docs/guide/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ module.exports = {
```ts
VueMacros({
root: '/your-project-path',

/**
* Vue version, 2 or 3.
*
Expand All @@ -152,6 +153,11 @@ VueMacros({
*/
unified: true,
},

// Disable features
hoistStatic: false,

// ... more features
})
```

Expand Down
40 changes: 40 additions & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@vue-macros/api",
"version": "0.0.0",
"packageManager": "pnpm@7.13.5",
"license": "MIT",
"homepage": "https://github.com/sxzz/unplugin-vue-macros#readme",
"bugs": {
"url": "https://github.com/sxzz/unplugin-vue-macros/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sxzz/unplugin-vue-macros.git"
},
"author": "三咲智子 <sxzz@sxzz.moe>",
"files": [
"dist"
],
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": "./*"
},
"scripts": {
"build": "tsup && tsx ../../scripts/postbuild.mts",
"dev": "DEV=1 tsup"
},
"dependencies": {
"@babel/types": "^7.19.4",
"@vue-macros/common": "workspace:~"
},
"devDependencies": {},
"engines": {
"node": ">=14.19.0"
}
}
5 changes: 5 additions & 0 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { MagicString } from '@vue-macros/common'

export * from './vue'
export * from './ts'
export * from './utils'
Loading