SuperAPI AI 工具集

use-vite

编程与开发

查看项目

更新于 10-15 21:52

技能介绍

用途:将 Vite 设为构建系统、Vitest 设为测试工具,并在构建过程中集成 TypeScript 类型检查。

主要能力:使用 ESM 方式编写 vite.config.js;通过 vite-plugin-checker 在开发时以浏览器浮层和终端显示类型错误,并在存在 TypeScript 错误时使构建失败,因此无需单独的 type-check 脚本。

使用方式:在 package.json 中添加 "type": "module",使所有 *.js 文件按 ESM 解释;必须保持 CJS 的文件改用 .cjs 扩展名。安装插件:pnpm add --save-dev vite-plugin-checker。在 vite.config.js 中引入并启用:import { defineConfig } from 'vite'; import checker from 'vite-plugin-checker'; export default defineConfig({ plugins: [checker({ typescript: true })] });

限制:不要使用 Vite Node API 的 CJS 构建,该方式已弃用并在 Vite 6 中移除。资料未提供 Vitest 的具体配置示例、其他命令或平台信息。