You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在运行vite build命令时指定使用的tsconfig文件?

解决Vite构建时指定自定义tsconfig.build.json的问题

方法1:在Vite配置文件中指定tsconfig路径

直接修改项目根目录的vite.config.ts,在配置里指定构建时使用的tsconfig文件:

import { defineConfig } from 'vite'
// 根据你的组件库框架引入对应插件,比如Vue的plugin-vue
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
  resolve: {
    typescript: {
      tsconfig: './tsconfig.build.json' // 填入你的构建专用tsconfig路径
    }
  }
})

方法2:通过命令行参数指定

执行构建命令时,直接用--tsconfig参数指定配置文件:

vite build --tsconfig ./tsconfig.build.json

嫌每次输入麻烦的话,把命令写到package.json的scripts里:

{
  "scripts": {
    "build": "vite build --tsconfig ./tsconfig.build.json"
  }
}

方法3:确认tsconfig.build.json的排除规则正确

确保你的构建专用配置文件已经精准排除Cypress相关内容,示例配置如下:

{
  "extends": "./tsconfig.json",
  "exclude": [
    "node_modules",
    "cypress/**/*",
    "src/**/*.cy.ts",
    "dist"
  ],
  "include": [
    "src/**/*"
  ]
}

内容的提问来源于stack exchange,提问作者Lazy Loading

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 22:20:26