This commit is contained in:
2026-05-07 02:15:20 +08:00
parent da0a6d0f81
commit ccc46844b6
141 changed files with 2358 additions and 1661 deletions
+1
View File
@@ -29,6 +29,7 @@
"build": "pnpm run gen-index && tsc -p tsconfig.build.json && vite build"
},
"devDependencies": {
"@rollup/plugin-typescript": "^12.3.0",
"@types/node": "^25.6.0",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
+4 -14
View File
@@ -1,22 +1,12 @@
{
// tsconfig.base.json,用于被 tesconfig.json 和 tesconfig.build.json 继承
"compilerOptions": {
// 输出模块语法,使用版本号最新的那个,而不是实验性语法 ESNext
"module": "es2022",
// 模块解析策略,模拟 Vite / Rollup / webpack,支持 exports / imports,不强制 Node ESM 的严格规则
"moduleResolution": "bundler",
// 显式声明使用的类型包
"types": ["node", "react"],
// 开启所有严格类型检查,防止 any / 隐式 any 扩散
"lib": ["ES2025", "DOM", "DOM.Iterable"],
"strict": true,
// 允许 ESM 导入 CJS
"esModuleInterop": true,
// 跳过 node_modules 类型检查,加快构建,避免第三方类型污染
"skipLibCheck": true
"skipLibCheck": true,
"isolatedModules": true,
"verbatimModuleSyntax": true
}
}
+2 -64
View File
@@ -1,74 +1,12 @@
{
// 此文件仅用于类型检查,不用于类型检查,构建时会指定使用 tsconfig.build.json
"extends": "./tsconfig.base.json",
"compilerOptions": {
// Browser api,需要加 "DOM","DOM.Iterable"
// Node api,需要加 "ES2025",始终使用带版本号的最新版本
// NextJs api,属于同构,server 端会预处理 DOM,计算url,三个都需要 "ES2025", "DOM", "DOM.Iterable"
"lib": ["ES2025", "DOM", "DOM.Iterable"],
/**
* 显式声明使用的类型包
* - node:Node.js API
* - react:JSX / React 类型
* - vite/client:import.meta / env
*/
"types": ["node", "react"],
/**
* React JSX 编译模式
* - 使用 React 17+ 新 JSX Transform
* - 不需要手动 import React
*/
"jsx": "react-jsx",
/**
* 编译输出目录
* - tsc / tsc -b 都会用到
*/
"outDir": "./dist",
/**
* 源码根目录
* - 确保 dist 结构与 src 一致
* - 对 declaration 路径至关重要
*/
"rootDir": "./src",
/**
* 生成 .d.ts 类型声明文件
* - 组件库 / npm 包发布必需
* - 对应用项目无害,仅影响类型输出
*/
"declaration": true,
/**
* 只做类型检查,不生成 JS 输出
* - 适用于 Vite / Next / Nuxt 等 bundler 场景
* - 防止 tsc 与构建工具重复 emit
*/
"noEmit": true,
/**
* 强制单文件可独立编译
* - 适配 esbuild / SWC / bundler 编译模型
* - 禁止依赖跨文件类型推断(enum / namespace 等)
*/
"isolatedModules": true
"jsx": "react-jsx",
"declaration": true
},
/**
* 参与类型检查和编译的文件
* - 只扫描 src
* - 其它目录通过 exclude 排除
*/
"include": ["src"],
/**
* 明确排除非源码内容
* - 避免污染类型系统
* - 防止误入 dist / test / config
* - 保证发布包干净
*/
"exclude": [
"node_modules",
"dist",
+3 -11
View File
@@ -1,16 +1,8 @@
{
// 此文件仅用于类型检查,不用于构建,构建时会指定使用 tsconfig.build.json
"extends": "./tsconfig.base.json",
"compilerOptions": {
// node api 使用最新版本号的 "ESxxxx",browser api 使用 "DOM" 和 "DOM.Iterable"
"lib": ["ES2025", "DOM", "DOM.Iterable"],
//显式声明使用的类型包,避免找不到模块
"types": ["node", "react"],
// React JSX 编译模式
"jsx": "react-jsx"
"jsx": "react-jsx",
"noEmit": true
},
// 将类型检查范围扩大至整个子项目,而不只是 src 文件夹,
"include": ["**/*"]
"include": ["."]
}
+4 -4
View File
@@ -2,6 +2,7 @@ import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import dts from "vite-plugin-dts";
import path from "path";
import typescript from "@rollup/plugin-typescript";
export default defineConfig({
plugins: [
@@ -11,6 +12,8 @@ export default defineConfig({
}),
],
esbuild: false,
build: {
lib: {
entry: path.resolve(__dirname, "src/index.ts"),
@@ -20,6 +23,7 @@ export default defineConfig({
},
rollupOptions: {
plugins: [typescript({ tsconfig: "./tsconfig.build.json" })],
external: ["react", "react-dom", "react/jsx-runtime"],
output: {
globals: {
@@ -31,9 +35,5 @@ export default defineConfig({
sourcemap: true,
cssCodeSplit: true,
watch: {
exclude: ["node_modules", "dist", ".git"],
},
},
});