├── .editorconfig
├── .eslintignore
├── .eslintrc.js
├── .gitignore
├── .prettierignore
├── .prettierrc
├── LICENSE
├── README.md
├── package.json
├── playground
├── .gitignore
├── .vscode
│ └── extensions.json
├── README.md
├── index.html
├── package.json
├── public
│ └── vite.svg
├── src
│ ├── App.vue
│ ├── assets
│ │ └── vue.svg
│ ├── components
│ │ └── HelloWorld.vue
│ ├── main.ts
│ ├── style.css
│ └── vite-env.d.ts
├── tsconfig.json
├── tsconfig.node.json
├── vite.config.ts
└── yarn.lock
├── pnpm-lock.yaml
├── scripts
└── postbuild.mts
├── src
├── core
│ ├── constants.ts
│ ├── magic-string.ts
│ ├── transform.ts
│ └── utils.ts
├── esbuild.ts
├── index.ts
├── rollup.ts
├── vite.ts
└── webpack.ts
├── tests
├── __snapshots__
│ └── rollup.test.ts.snap
├── fixtures
│ ├── index.ts
│ ├── index1.ts
│ ├── index2.ts
│ ├── index3.ts
│ ├── index4.ts
│ ├── index5.ts
│ ├── typescript-global.vue
│ ├── typescript.vue
│ ├── typescript.vue.NotSupport
│ ├── typescript1.vue
│ ├── typescript10.vue
│ ├── typescript11.vue
│ ├── typescript12.vue
│ ├── typescript13.vue
│ ├── typescript14.vue
│ ├── typescript2.vue
│ ├── typescript3.vue
│ ├── typescript4.vue
│ ├── typescript5.vue
│ ├── typescript6.vue
│ ├── typescript7.vue
│ └── typescriptNormal.vue
├── rollup.test.ts
├── tsconfig.json
└── types
│ └── index.ts
├── tsconfig.json
├── tsup.config.ts
└── vite.config.ts
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_size = 2
5 | end_of_line = lf
6 | insert_final_newline = true
7 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | pnpm-lock.yaml
4 | tests/fixtures
5 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | const { defineConfig } = require('eslint-define-config')
2 |
3 | module.exports = defineConfig({
4 | extends: ['@sxzz/eslint-config-vue', '@sxzz/eslint-config-prettier'],
5 | })
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | .DS_Store
4 | .pnpm-debug.log*
5 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | pnpm-lock.yaml
4 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "semi": false,
3 | "singleQuote": true
4 | }
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Albert Liu
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # unplugin-vue-import-props
2 |
3 | Add import define props type support for Vue script-setup and lang is typescript,now support global types.
4 |
5 | 在Vue3中使用此款插件,传递给 defineProps 的泛型参数可以是一个导入的类型,现在已支持全局类型。
6 |
7 | ## Usage
8 |
9 | ### Basic example
10 |
11 | app.vue
12 | ```vue
13 |
17 | ```
18 | app.ts
19 | ```typescript
20 | export interface Test {
21 | name: string
22 | }
23 | ```
24 |
25 |
26 | Output
27 |
28 | ```vue
29 |
33 | ```
34 |
35 |
36 |
37 | app.vue
38 | ```vue
39 |
43 | ```
44 | app.ts
45 | ```typescript
46 | export interface Foo {
47 | name: string
48 | }
49 | ```
50 |
51 |
52 | Output
53 |
54 | ```vue
55 |
59 | ```
60 |
61 |
62 |
63 | ## Installation
64 |
65 | ```bash
66 | npm i unplugin-vue-import-props -D
67 | ```
68 |
69 | If you want use `typeRoot` to set global types path, please add configPath like:
70 |
71 | ```ts
72 | // vite.config.ts
73 | import ImportProps from 'unplugin-vue-import-props/vite'
74 | import Vue from '@vitejs/plugin-vue'
75 | import { resolve } from 'path'
76 |
77 | export default defineConfig({
78 | plugins: [Vue(), ImportProps({
79 | configPath: resolve(__dirname, './tsconfig.json')
80 | })],
81 | })
82 | ```
83 |
84 | now you can use global types.
85 |
86 |
87 | Vite
88 |
89 | ```ts
90 | // vite.config.ts
91 | import ImportProps from 'unplugin-vue-import-props/vite'
92 | import Vue from '@vitejs/plugin-vue'
93 |
94 | export default defineConfig({
95 | plugins: [Vue(), ImportProps()],
96 | })
97 | ```
98 |
99 |
100 |
101 |
102 | Rollup
103 |
104 | ```ts
105 | // rollup.config.js
106 | import ImportProps from 'unplugin-vue-import-props/rollup'
107 |
108 | export default {
109 | plugins: [ImportProps()], // Must be before Vue plugin!
110 | }
111 | ```
112 |
113 |
114 |
115 |
116 | esbuild
117 |
118 | ```ts
119 | // esbuild.config.js
120 | import { build } from 'esbuild'
121 |
122 | build({
123 | plugins: [
124 | require('unplugin-vue-import-props/esbuild')(), // Must be before Vue plugin!
125 | ],
126 | })
127 | ```
128 |
129 |
130 |
131 |
132 | Webpack
133 |
134 | ```ts
135 | // webpack.config.js
136 | module.exports = {
137 | /* ... */
138 | plugins: [require('unplugin-vue-import-props/webpack')()],
139 | }
140 | ```
141 |
142 |
143 |
144 |
145 | Vue CLI
146 |
147 | ```ts
148 | // vue.config.js
149 | module.exports = {
150 | configureWebpack: {
151 | plugins: [require('unplugin-vue-import-props/webpack')()],
152 | },
153 | }
154 | ```
155 |
156 |
157 |
158 | #### TypeScript Support
159 |
160 | ```jsonc
161 | // tsconfig.json
162 | {
163 | "compilerOptions": {
164 | // ...
165 | "types": ["unplugin-vue-import-props" /* ... */]
166 | }
167 | }
168 | ```
169 | #### Related articles
170 |
171 | https://www.yuque.com/docs/share/4bd70f56-a3e2-4296-843c-08550288c70f?#
172 |
173 |
174 | Plugin Template: [unplugin-vue-macros](https://github.com/sxzz/unplugin-vue-macros)
175 |
176 | > With great appreciation to this project [unplugin-vue-macros](https://github.com/sxzz/unplugin-vue-macros) and its owners [三咲智子](https://github.com/sxzz) and [contributors](https://github.com/sxzz/unplugin-vue-macros/graphs/contributors), this project was created using this project as a template
177 |
178 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "unplugin-vue-import-props",
3 | "version": "0.0.7-beta.2",
4 | "packageManager": "pnpm@7.5.0",
5 | "description": "Add import define props type support for Vue script-setup and lang is typescript",
6 | "keywords": [
7 | "unplugin",
8 | "vue",
9 | "script-setup",
10 | "defineProps",
11 | "typescript"
12 | ],
13 | "license": "MIT",
14 | "author": "liulinboyi ",
15 | "homepage": "https://github.com/liulinboyi/unplugin-vue-import-props",
16 | "bugs": {
17 | "url": "https://github.com/liulinboyi/unplugin-vue-import-props/issues"
18 | },
19 | "repository": {
20 | "type": "git",
21 | "url": "git+https://github.com/liulinboyi/unplugin-vue-import-props.git"
22 | },
23 | "files": [
24 | "dist"
25 | ],
26 | "main": "dist/index.js",
27 | "module": "dist/index.mjs",
28 | "types": "index.d.ts",
29 | "exports": {
30 | ".": {
31 | "types": "./dist/index.d.ts",
32 | "require": "./dist/index.js",
33 | "import": "./dist/index.mjs"
34 | },
35 | "./vite": {
36 | "types": "./dist/vite.d.ts",
37 | "require": "./dist/vite.js",
38 | "import": "./dist/vite.mjs"
39 | },
40 | "./webpack": {
41 | "types": "./dist/webpack.d.ts",
42 | "require": "./dist/webpack.js",
43 | "import": "./dist/webpack.mjs"
44 | },
45 | "./rollup": {
46 | "types": "./dist/rollup.d.ts",
47 | "require": "./dist/rollup.js",
48 | "import": "./dist/rollup.mjs"
49 | },
50 | "./esbuild": {
51 | "types": "./dist/esbuild.d.ts",
52 | "require": "./dist/esbuild.js",
53 | "import": "./dist/esbuild.mjs"
54 | },
55 | "./*": "./*"
56 | },
57 | "typesVersions": {
58 | "*": {
59 | "*": [
60 | "./dist/*",
61 | "./*"
62 | ]
63 | }
64 | },
65 | "scripts": {
66 | "test": "vitest",
67 | "build": "cross-env rimraf dist && tsup && tsx scripts/postbuild.mts",
68 | "dev": "cross-env MODE=dev tsup",
69 | "release": "bumpp",
70 | "lint": "eslint . --ext .vue,.ts,.md,.json --max-warnings 0"
71 | },
72 | "peerDependencies": {
73 | "vue": "^3.2.25"
74 | },
75 | "dependencies": {
76 | "@rollup/pluginutils": "^4.2.1",
77 | "@vue/compiler-sfc": "^3.2.37",
78 | "@vue/compiler-core": "^3.2.40",
79 | "@vue/compiler-dom": "^3.2.40",
80 | "unplugin": "^1.3.1",
81 | "@babel/generator": "^7.19.5",
82 | "@babel/parser": "^7.19.4",
83 | "typescript": "^4.7.4",
84 | "magic-string": "^0.26.7"
85 | },
86 | "devDependencies": {
87 | "@types/babel__generator": "^7.6.4",
88 | "@babel/types": "^7.18.8",
89 | "@sxzz/eslint-config-prettier": "^2.3.1",
90 | "@sxzz/eslint-config-vue": "^2.3.1",
91 | "@types/node": "*",
92 | "@vitest/ui": "^0.18.0",
93 | "bumpp": "^8.2.1",
94 | "cross-env": "^7.0.3",
95 | "eslint": "^8.19.0",
96 | "eslint-define-config": "^1.5.1",
97 | "fast-glob": "^3.2.11",
98 | "rimraf": "^3.0.2",
99 | "rollup": "^2.76.0",
100 | "tsup": "^6.1.3",
101 | "tsx": "^3.8.0",
102 | "unplugin-vue": "^3.0.0-beta.0",
103 | "vite": "^3.0.0",
104 | "vitest": "^0.18.0",
105 | "vue": "^3.2.37"
106 | },
107 | "engines": {
108 | "node": ">=14.19.0"
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/playground/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | *.local
14 |
15 | # Editor directories and files
16 | .vscode/*
17 | !.vscode/extensions.json
18 | .idea
19 | .DS_Store
20 | *.suo
21 | *.ntvs*
22 | *.njsproj
23 | *.sln
24 | *.sw?
25 |
--------------------------------------------------------------------------------
/playground/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": ["Vue.volar"]
3 | }
4 |
--------------------------------------------------------------------------------
/playground/README.md:
--------------------------------------------------------------------------------
1 | # Vue 3 + TypeScript + Vite
2 |
3 | This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `
12 |