vite 构建自动生成 .d.ts 声明文件
首先调整 build 脚本顺序:
json
"scripts": {
"dev": "vite",
"build": "vue-tsc && vite build",
"build": "vite build && vue-tsc",
"preview": "vite preview"
},然后调整 tsconfig.json 的内容:
json
{
"compiler": {
"noEmit": true,
"noEmit": false,
// 只输出声明文件产物
"emitDeclarationOnly": true,
// 自动生成声明文件
"declaration": true,
// 生成的声明文件存放目录
"declarationDir": "dist",
}
}再次执行 build 脚本,会发现构建后的目录中存在 .d.ts 文件。