English | 中文
A vite plugin that generate .d.ts
files from .ts
or .vue
source files for lib.
yarn add vite-plugin-dts -D
import { resolve } from 'path'
import { defineConfig } from 'vite'
import dts from 'vite-plugin-dts'
export default defineConfig({
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: 'MyLib',
formats: ['es'],
fileName: 'my-lib'
}
},
plugins: [dts()]
})
import type { ts } from 'ts-morph'
interface TransformWriteFile {
filePath?: string
content?: string
}
export interface PluginOptions {
// Depends on the root directory
// Defaults base on your vite config root options
root?: string
// Declaration files output directory
// Defaults base on your vite config output options
outputDir?: string
// Project init compilerOptions using by ts-morph
// Default: null
compilerOptions?: ts.CompilerOptions | null
// Project init tsconfig.json file path by ts-morph
// Plugin also resolve incldue and exclude files from tsconfig.json
// Default: 'tsconfig.json'
tsConfigFilePath?: string
// Whether transform file name '.vue.d.ts' to '.d.ts'
// Default: false
cleanVueFileName?: boolean
// Whether transform dynamic import to static
// eg. 'import('vue').DefineComponent' to 'import { DefineComponent } from "vue"'
// Default: false
staticImport?: boolean
// Manual set include glob
// Defaults base on your tsconfig.json include option
include?: string | string[]
// Manual set exclude glob
// Defaults base on your tsconfig.json exclude option, be 'node_module/**' when empty
exclude?: string | string[]
// Whether generate types entry file
// When true will from package.json types field if exists or `${outputDir}/index.d.ts`
// Default: false
insertTypesEntry?: boolean
// Before declaration file be writed hook
// You can transform declaration file-path and content through it
// Default: () => {}
beforeWriteFile?: (filePath: string, content: string) => void | TransformWriteFile
}
Clone and run the following script:
yarn run test:e2e
Then check example/types
.
MIT License.