vite-plugin-dts 0.9.4 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +174 -174
- package/README.zh-CN.md +173 -173
- package/dist/index.js +10951 -8292
- package/dist/index.mjs +10960 -8293
- package/package.json +19 -19
package/README.md
CHANGED
|
@@ -1,174 +1,174 @@
|
|
|
1
|
-
# vite-plugin-dts
|
|
2
|
-
|
|
3
|
-
**English** | [中文](./README.zh-CN.md)
|
|
4
|
-
|
|
5
|
-
A vite plugin that generate `.d.ts` files from `.ts` or `.vue` source files for lib.
|
|
6
|
-
|
|
7
|
-
## Install
|
|
8
|
-
|
|
9
|
-
```sh
|
|
10
|
-
yarn add vite-plugin-dts -D
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
In `vite.config.ts`:
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
import { resolve } from 'path'
|
|
19
|
-
import { defineConfig } from 'vite'
|
|
20
|
-
import dts from 'vite-plugin-dts'
|
|
21
|
-
|
|
22
|
-
export default defineConfig({
|
|
23
|
-
build: {
|
|
24
|
-
lib: {
|
|
25
|
-
entry: resolve(__dirname, 'src/index.ts'),
|
|
26
|
-
name: 'MyLib',
|
|
27
|
-
formats: ['es'],
|
|
28
|
-
fileName: 'my-lib'
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
plugins: [dts()]
|
|
32
|
-
})
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
In your component:
|
|
36
|
-
|
|
37
|
-
```vue
|
|
38
|
-
<template>
|
|
39
|
-
<div></div>
|
|
40
|
-
</template>
|
|
41
|
-
|
|
42
|
-
<script lang="ts">
|
|
43
|
-
// using defineComponent for inferring types
|
|
44
|
-
import { defineComponent } from 'vue'
|
|
45
|
-
|
|
46
|
-
export default defineComponent({
|
|
47
|
-
name: 'Component'
|
|
48
|
-
})
|
|
49
|
-
</script>
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
```vue
|
|
53
|
-
<script setup lang="ts">
|
|
54
|
-
// Need to access the defineProps returned value to
|
|
55
|
-
// infer types although you never use the props directly
|
|
56
|
-
const props = defineProps<{
|
|
57
|
-
color: 'blue' | 'red'
|
|
58
|
-
}>()
|
|
59
|
-
</script>
|
|
60
|
-
|
|
61
|
-
<template>
|
|
62
|
-
<div>{{ color }}</div>
|
|
63
|
-
</template>
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Options
|
|
67
|
-
|
|
68
|
-
```ts
|
|
69
|
-
import type { ts, Diagnostic } from 'ts-morph'
|
|
70
|
-
|
|
71
|
-
interface TransformWriteFile {
|
|
72
|
-
filePath?: string
|
|
73
|
-
content?: string
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface PluginOptions {
|
|
77
|
-
// Depends on the root directory
|
|
78
|
-
// Defaults base on your vite config root options
|
|
79
|
-
root?: string
|
|
80
|
-
|
|
81
|
-
// Declaration files output directory
|
|
82
|
-
// Defaults base on your vite config output options
|
|
83
|
-
outputDir?: string
|
|
84
|
-
|
|
85
|
-
// Project init compilerOptions using by ts-morph
|
|
86
|
-
// Default: null
|
|
87
|
-
compilerOptions?: ts.CompilerOptions | null
|
|
88
|
-
|
|
89
|
-
// Project init tsconfig.json file path by ts-morph
|
|
90
|
-
// Plugin also resolve incldue and exclude files from tsconfig.json
|
|
91
|
-
// Default: 'tsconfig.json'
|
|
92
|
-
tsConfigFilePath?: string
|
|
93
|
-
|
|
94
|
-
// Whether transform file name '.vue.d.ts' to '.d.ts'
|
|
95
|
-
// Default: false
|
|
96
|
-
cleanVueFileName?: boolean
|
|
97
|
-
|
|
98
|
-
// Whether transform dynamic import to static
|
|
99
|
-
// eg. 'import('vue').DefineComponent' to 'import { DefineComponent } from "vue"'
|
|
100
|
-
// Default: false
|
|
101
|
-
staticImport?: boolean
|
|
102
|
-
|
|
103
|
-
// Manual set include glob
|
|
104
|
-
// Defaults base on your tsconfig.json include option
|
|
105
|
-
include?: string | string[]
|
|
106
|
-
|
|
107
|
-
// Manual set exclude glob
|
|
108
|
-
// Defaults base on your tsconfig.json exclude option, be 'node_module/**' when empty
|
|
109
|
-
exclude?: string | string[]
|
|
110
|
-
|
|
111
|
-
// Whether generate types entry file
|
|
112
|
-
// When true will from package.json types field if exists or `${outputDir}/index.d.ts`
|
|
113
|
-
// Default: false
|
|
114
|
-
insertTypesEntry?: boolean
|
|
115
|
-
|
|
116
|
-
// Whether copy .d.ts source files into outputDir
|
|
117
|
-
// Default: true
|
|
118
|
-
copyDtsFiles?: boolean
|
|
119
|
-
|
|
120
|
-
// Whether emit nothing when has any diagnostic
|
|
121
|
-
// Default: false
|
|
122
|
-
noEmitOnError?: boolean
|
|
123
|
-
|
|
124
|
-
// Whether skip typescript diagnostics
|
|
125
|
-
// Skip type diagnostics means that type errors will not interrupt the build process
|
|
126
|
-
// But for the source files with type errors will not be emitted
|
|
127
|
-
// Default: true
|
|
128
|
-
skipDiagnostics?: boolean
|
|
129
|
-
|
|
130
|
-
// Whether log diagnostic informations
|
|
131
|
-
// Not effective when `skipDiagnostics` is true
|
|
132
|
-
// Default: false
|
|
133
|
-
logDiagnostics?: boolean
|
|
134
|
-
|
|
135
|
-
// After emit diagnostic hook
|
|
136
|
-
// According to the length to judge whether there is any type error
|
|
137
|
-
// Default: () => {}
|
|
138
|
-
afterDiagnostic?: (diagnostics: Diagnostic[]) => void | Promise<void>
|
|
139
|
-
|
|
140
|
-
// Before declaration file be writed hook
|
|
141
|
-
// You can transform declaration file-path and content through it
|
|
142
|
-
// Default: () => {}
|
|
143
|
-
beforeWriteFile?: (filePath: string, content: string) => void | TransformWriteFile
|
|
144
|
-
|
|
145
|
-
// After build hook
|
|
146
|
-
// It wil be called after all declaration files are written
|
|
147
|
-
// Default: () => {}
|
|
148
|
-
afterBuild?: () => void | Promise<void>
|
|
149
|
-
}
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
## Example
|
|
153
|
-
|
|
154
|
-
Clone and run the following script:
|
|
155
|
-
|
|
156
|
-
```sh
|
|
157
|
-
yarn run test:e2e
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
Then check `example/types`.
|
|
161
|
-
|
|
162
|
-
## FAQ
|
|
163
|
-
|
|
164
|
-
Here will include some FAQ's and provide some solutions.
|
|
165
|
-
|
|
166
|
-
### Missing some declaration files after build
|
|
167
|
-
|
|
168
|
-
By default `skipDiagnostics` option is `true`, which means that type diagnostic will be skipped during the build process (some projects may have diagnostic tool such as `vue-tsc`). If there are some files with type errors which will interrupt the build process, these files will not be emitted (not generate declaration files).
|
|
169
|
-
|
|
170
|
-
If your project has not type diagnostic tools, you can set `skipDiagnostics: false` and `logDiagnostics: true` to turn on the diagnostic and log features of this plugin. It will help you to check the type errors during build and log error information to the terminal.
|
|
171
|
-
|
|
172
|
-
## License
|
|
173
|
-
|
|
174
|
-
MIT License.
|
|
1
|
+
# vite-plugin-dts
|
|
2
|
+
|
|
3
|
+
**English** | [中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
A vite plugin that generate `.d.ts` files from `.ts` or `.vue` source files for lib.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
yarn add vite-plugin-dts -D
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
In `vite.config.ts`:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { resolve } from 'path'
|
|
19
|
+
import { defineConfig } from 'vite'
|
|
20
|
+
import dts from 'vite-plugin-dts'
|
|
21
|
+
|
|
22
|
+
export default defineConfig({
|
|
23
|
+
build: {
|
|
24
|
+
lib: {
|
|
25
|
+
entry: resolve(__dirname, 'src/index.ts'),
|
|
26
|
+
name: 'MyLib',
|
|
27
|
+
formats: ['es'],
|
|
28
|
+
fileName: 'my-lib'
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
plugins: [dts()]
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
In your component:
|
|
36
|
+
|
|
37
|
+
```vue
|
|
38
|
+
<template>
|
|
39
|
+
<div></div>
|
|
40
|
+
</template>
|
|
41
|
+
|
|
42
|
+
<script lang="ts">
|
|
43
|
+
// using defineComponent for inferring types
|
|
44
|
+
import { defineComponent } from 'vue'
|
|
45
|
+
|
|
46
|
+
export default defineComponent({
|
|
47
|
+
name: 'Component'
|
|
48
|
+
})
|
|
49
|
+
</script>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```vue
|
|
53
|
+
<script setup lang="ts">
|
|
54
|
+
// Need to access the defineProps returned value to
|
|
55
|
+
// infer types although you never use the props directly
|
|
56
|
+
const props = defineProps<{
|
|
57
|
+
color: 'blue' | 'red'
|
|
58
|
+
}>()
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<template>
|
|
62
|
+
<div>{{ color }}</div>
|
|
63
|
+
</template>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Options
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import type { ts, Diagnostic } from 'ts-morph'
|
|
70
|
+
|
|
71
|
+
interface TransformWriteFile {
|
|
72
|
+
filePath?: string
|
|
73
|
+
content?: string
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface PluginOptions {
|
|
77
|
+
// Depends on the root directory
|
|
78
|
+
// Defaults base on your vite config root options
|
|
79
|
+
root?: string
|
|
80
|
+
|
|
81
|
+
// Declaration files output directory
|
|
82
|
+
// Defaults base on your vite config output options
|
|
83
|
+
outputDir?: string
|
|
84
|
+
|
|
85
|
+
// Project init compilerOptions using by ts-morph
|
|
86
|
+
// Default: null
|
|
87
|
+
compilerOptions?: ts.CompilerOptions | null
|
|
88
|
+
|
|
89
|
+
// Project init tsconfig.json file path by ts-morph
|
|
90
|
+
// Plugin also resolve incldue and exclude files from tsconfig.json
|
|
91
|
+
// Default: 'tsconfig.json'
|
|
92
|
+
tsConfigFilePath?: string
|
|
93
|
+
|
|
94
|
+
// Whether transform file name '.vue.d.ts' to '.d.ts'
|
|
95
|
+
// Default: false
|
|
96
|
+
cleanVueFileName?: boolean
|
|
97
|
+
|
|
98
|
+
// Whether transform dynamic import to static
|
|
99
|
+
// eg. 'import('vue').DefineComponent' to 'import { DefineComponent } from "vue"'
|
|
100
|
+
// Default: false
|
|
101
|
+
staticImport?: boolean
|
|
102
|
+
|
|
103
|
+
// Manual set include glob
|
|
104
|
+
// Defaults base on your tsconfig.json include option
|
|
105
|
+
include?: string | string[]
|
|
106
|
+
|
|
107
|
+
// Manual set exclude glob
|
|
108
|
+
// Defaults base on your tsconfig.json exclude option, be 'node_module/**' when empty
|
|
109
|
+
exclude?: string | string[]
|
|
110
|
+
|
|
111
|
+
// Whether generate types entry file
|
|
112
|
+
// When true will from package.json types field if exists or `${outputDir}/index.d.ts`
|
|
113
|
+
// Default: false
|
|
114
|
+
insertTypesEntry?: boolean
|
|
115
|
+
|
|
116
|
+
// Whether copy .d.ts source files into outputDir
|
|
117
|
+
// Default: true
|
|
118
|
+
copyDtsFiles?: boolean
|
|
119
|
+
|
|
120
|
+
// Whether emit nothing when has any diagnostic
|
|
121
|
+
// Default: false
|
|
122
|
+
noEmitOnError?: boolean
|
|
123
|
+
|
|
124
|
+
// Whether skip typescript diagnostics
|
|
125
|
+
// Skip type diagnostics means that type errors will not interrupt the build process
|
|
126
|
+
// But for the source files with type errors will not be emitted
|
|
127
|
+
// Default: true
|
|
128
|
+
skipDiagnostics?: boolean
|
|
129
|
+
|
|
130
|
+
// Whether log diagnostic informations
|
|
131
|
+
// Not effective when `skipDiagnostics` is true
|
|
132
|
+
// Default: false
|
|
133
|
+
logDiagnostics?: boolean
|
|
134
|
+
|
|
135
|
+
// After emit diagnostic hook
|
|
136
|
+
// According to the length to judge whether there is any type error
|
|
137
|
+
// Default: () => {}
|
|
138
|
+
afterDiagnostic?: (diagnostics: Diagnostic[]) => void | Promise<void>
|
|
139
|
+
|
|
140
|
+
// Before declaration file be writed hook
|
|
141
|
+
// You can transform declaration file-path and content through it
|
|
142
|
+
// Default: () => {}
|
|
143
|
+
beforeWriteFile?: (filePath: string, content: string) => void | TransformWriteFile
|
|
144
|
+
|
|
145
|
+
// After build hook
|
|
146
|
+
// It wil be called after all declaration files are written
|
|
147
|
+
// Default: () => {}
|
|
148
|
+
afterBuild?: () => void | Promise<void>
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Example
|
|
153
|
+
|
|
154
|
+
Clone and run the following script:
|
|
155
|
+
|
|
156
|
+
```sh
|
|
157
|
+
yarn run test:e2e
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Then check `example/types`.
|
|
161
|
+
|
|
162
|
+
## FAQ
|
|
163
|
+
|
|
164
|
+
Here will include some FAQ's and provide some solutions.
|
|
165
|
+
|
|
166
|
+
### Missing some declaration files after build
|
|
167
|
+
|
|
168
|
+
By default `skipDiagnostics` option is `true`, which means that type diagnostic will be skipped during the build process (some projects may have diagnostic tool such as `vue-tsc`). If there are some files with type errors which will interrupt the build process, these files will not be emitted (not generate declaration files).
|
|
169
|
+
|
|
170
|
+
If your project has not type diagnostic tools, you can set `skipDiagnostics: false` and `logDiagnostics: true` to turn on the diagnostic and log features of this plugin. It will help you to check the type errors during build and log error information to the terminal.
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
MIT License.
|