@flywen/tsconfig 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # @flywen/ts-config
2
+
3
+ Shared TypeScript configurations for multiple environments.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -D @flywen/ts-config
9
+ # or
10
+ yarn add -D @flywen/ts-config
11
+ # or
12
+ pnpm add -D @flywen/ts-config
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Extend the configuration in your `tsconfig.json`:
18
+
19
+ ### Base Configuration (tsconfig.base.json)
20
+
21
+ ```json
22
+ {
23
+ "extends": "@flywen/ts-config/tsconfig.base.json"
24
+ }
25
+ ```
26
+
27
+ ### Node.js Application (tsconfig.node.json)
28
+
29
+ For Node.js applications (not libraries):
30
+
31
+ ```json
32
+ {
33
+ "extends": "@flywen/ts-config/tsconfig.node.json"
34
+ }
35
+ ```
36
+
37
+ ### Node.js Library (tsconfig.node-lib.json)
38
+
39
+ For Node.js libraries that need declaration files:
40
+
41
+ ```json
42
+ {
43
+ "extends": "@flywen/ts-config/tsconfig.node-lib.json"
44
+ }
45
+ ```
46
+
47
+ ### React (tsconfig.react.json)
48
+
49
+ For React applications with Vite/modern bundlers:
50
+
51
+ ```json
52
+ {
53
+ "extends": "@flywen/ts-config/tsconfig.react.json"
54
+ }
55
+ ```
56
+
57
+ ### Vue (tsconfig.vue.json)
58
+
59
+ For Vue 3 applications with Vite:
60
+
61
+ ```json
62
+ {
63
+ "extends": "@flywen/ts-config/tsconfig.vue.json"
64
+ }
65
+ ```
66
+
67
+ ### Web Library (tsconfig.web-lib.json)
68
+
69
+ For web libraries that need declaration files:
70
+
71
+ ```json
72
+ {
73
+ "extends": "@flywen/ts-config/tsconfig.web-lib.json"
74
+ }
75
+ ```
76
+
77
+ ## Configurations
78
+
79
+ ### tsconfig.base.json
80
+
81
+ Base configuration with shared settings:
82
+ - All strict mode options enabled
83
+ - `esModuleInterop: true`
84
+ - `skipLibCheck: true`
85
+ - `forceConsistentCasingInFileNames: true`
86
+ - `resolveJsonModule: true`
87
+ - `declaration: true`
88
+ - `declarationMap: true`
89
+ - `sourceMap: true`
90
+
91
+ ### tsconfig.node.json
92
+
93
+ Node.js 18+ application configuration:
94
+ - `target: "ES2022"`
95
+ - `module: "NodeNext"`
96
+ - `moduleResolution: "NodeNext"`
97
+ - `lib: ["ES2022"]`
98
+ - `outDir: "./dist"`
99
+ - `rootDir: "./src"`
100
+ - `types: ["node"]`
101
+
102
+ ### tsconfig.node-lib.json
103
+
104
+ Node.js library configuration:
105
+ - Inherits from base
106
+ - `target: "ES2022"`
107
+ - `module: "NodeNext"`
108
+ - `moduleResolution: "NodeNext"`
109
+ - `declaration: true`
110
+ - `declarationMap: true`
111
+ - `types: ["node"]`
112
+
113
+ ### tsconfig.react.json
114
+
115
+ React (Vite/modern bundler) configuration:
116
+ - `target: "ESNext"`
117
+ - `module: "ESNext"`
118
+ - `moduleResolution: "bundler"`
119
+ - `jsx: "react-jsx"`
120
+ - `jsxImportSource: "react"`
121
+ - `lib: ["DOM", "DOM.Iterable", "ESNext"]`
122
+ - `noEmit: true` (Vite handles compilation)
123
+ - Path aliases configured (`@/*`)
124
+
125
+ ### tsconfig.vue.json
126
+
127
+ Vue 3 (Vite) configuration:
128
+ - `target: "ESNext"`
129
+ - `module: "ESNext"`
130
+ - `moduleResolution: "bundler"`
131
+ - `jsx: "preserve"`
132
+ - `jsxImportSource: "vue"`
133
+ - `lib: ["ESNext", "DOM", "DOM.Iterable"]`
134
+ - `types: ["vite/client"]`
135
+ - `noEmit: true` (Vite handles compilation)
136
+ - Path aliases configured (`@/*`)
137
+ - Includes `.vue` files
138
+
139
+ ### tsconfig.web-lib.json
140
+
141
+ Web library configuration:
142
+ - `target: "ES2020"`
143
+ - `module: "ESNext"`
144
+ - `moduleResolution: "bundler"`
145
+ - `lib: ["ESNext", "DOM", "DOM.Iterable"]`
146
+ - `declaration: true`
147
+ - `declarationMap: true`
148
+ - `outDir: "./dist"`
149
+ - `rootDir: "./src"`
150
+
151
+ ## Notes
152
+
153
+ - All configurations extend from `tsconfig.base.json`
154
+ - React and Vue configs assume usage with Vite or similar modern bundlers
155
+ - Node.js configs support both ESM (`NodeNext`) and CJS
156
+ - Path aliases (`@/*`) are pre-configured for React, Vue, and web-lib configs
157
+
158
+ ## License
159
+
160
+ MIT
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@flywen/tsconfig",
3
+ "version": "1.0.0",
4
+ "description": "Shared TypeScript configurations for multiple environments (Node.js, React, Vue, Web Library)",
5
+ "type": "module",
6
+ "files": [
7
+ "tsconfig.base.json",
8
+ "tsconfig.node.json",
9
+ "tsconfig.node-lib.json",
10
+ "tsconfig.react.json",
11
+ "tsconfig.vue.json",
12
+ "tsconfig.web-lib.json"
13
+ ],
14
+ "keywords": [
15
+ "typescript",
16
+ "tsconfig",
17
+ "configuration",
18
+ "node",
19
+ "react",
20
+ "vue",
21
+ "library",
22
+ "web"
23
+ ],
24
+ "author": "flywen",
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/goatail/tsconfig.git"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/gotail/tsconfig/issues"
32
+ },
33
+ "homepage": "https://github.com/gotail/tsconfig#readme",
34
+ "publishConfig": {
35
+ "access": "public"
36
+ }
37
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* ========== 严格检查(所有配置共享) ========== */
4
+ "strict": true, // 开启所有严格类型检查(类型安全的基石)
5
+ "noImplicitAny": true, // 禁止隐式 any 类型,强制显式声明类型
6
+ "strictNullChecks": true, // 严格 null/undefined 检查,避免空指针错误
7
+ "strictFunctionTypes": true, // 严格函数类型检查,防止参数类型错误
8
+ "strictBindCallApply": true, // 严格 bind/call/apply 检查
9
+ "strictPropertyInitialization": true, // 严格属性初始化检查(类属性必须初始化)
10
+ "noImplicitThis": true, // 禁止隐式 this,必须显式声明 this 类型
11
+ "alwaysStrict": true, // 始终以严格模式解析(生成 "use strict")
12
+
13
+ /* ========== 模块解析通用配置 ========== */
14
+ "esModuleInterop": true, // 允许 CommonJS 和 ES Module 互操作(如 import * as fs from 'fs')
15
+ "forceConsistentCasingInFileNames": true, // 强制文件名大小写一致(避免 macOS/Windows 不兼容)
16
+ "resolveJsonModule": true, // 允许导入 .json 文件(如 import config from './config.json')
17
+ "skipLibCheck": true, // 跳过 node_modules 类型检查(加快编译速度)
18
+
19
+ /* ========== 通用输出配置 ========== */
20
+ "declaration": true, // 生成 .d.ts 类型声明文件(库项目必须)
21
+ "declarationMap": true, // 生成 .d.ts.map 源码映射(允许用户跳转到源码)
22
+ "sourceMap": true, // 生成 .js.map 源码映射(便于调试)
23
+
24
+ /* ========== 其他通用配置 ========== */
25
+ "removeComments": false // 保留注释(库项目重要,JSDoc 注释会包含在 .d.ts 中)
26
+ },
27
+ "exclude": ["node_modules", "dist", "build"]
28
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "extends": "./tsconfig.base.json",
3
+
4
+ "compilerOptions": {
5
+ /* ========== Node.js 库配置(继承 base.json) ========== */
6
+ "target": "ES2022", // Node.js 18+ 推荐使用 ES2022(支持 Top-level await)
7
+ "module": "NodeNext", // Node.js 原生 ESM/CJS 双模式支持
8
+ "moduleResolution": "NodeNext", // 配合 NodeNext,遵循 Node.js 文件寻址规则
9
+ "lib": ["ES2022"], // 仅包含 ES 语法,不含 DOM
10
+
11
+ /* ========== 库的产物配置 ========== */
12
+ "declaration": true, // 必须!生成 .d.ts 文件,库的使用者才能看到类型提示
13
+ "declarationMap": true, // 生成 .d.ts.map,允许使用者调试时跳转到你的 TS 源码
14
+ "sourceMap": true, // 生成 .js.map,方便在 Node 中进行错误堆栈追踪
15
+ "outDir": "./dist", // 编译后的文件存放路径
16
+ "rootDir": "./src", // 源码根目录
17
+
18
+ /* ========== Node.js 类型注入 ========== */
19
+ "types": ["node"] // 显式引入 @types/node,确保可以使用 process, fs, path 等
20
+ },
21
+
22
+ "include": ["src/**/*.ts"], // 仅包含源码
23
+ "exclude": ["node_modules", "dist", "test", "**/*.spec.ts", "**/*.test.ts"] // 排除测试文件和产物
24
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "extends": "./tsconfig.base.json",
3
+
4
+ "compilerOptions": {
5
+ /* ========== Node.js 应用配置(继承 base.json) ========== */
6
+ "target": "ES2022", // Node.js 18+ 推荐使用 ES2022(支持 Top-level await)
7
+ "module": "NodeNext", // Node.js 原生 ESM/CJS 双模式支持
8
+ "moduleResolution": "NodeNext", // 配合 NodeNext,遵循 Node.js 文件寻址规则
9
+ "lib": ["ES2022"], // 仅包含 ES 语法,不含 DOM(Node 无浏览器 API)
10
+
11
+ /* ========== 应用输出配置 ========== */
12
+ "outDir": "./dist", // 编译产物输出目录
13
+ "rootDir": "./src", // 源码根目录
14
+ "removeComments": false, // 保留注释(便于调试和阅读)
15
+
16
+ /* ========== Node.js 特定类型 ========== */
17
+ "types": ["node"], // 注入 Node.js 类型(process, fs, path 等)
18
+ "sourceMap": true // 生成 source map(便于 Node 错误堆栈追踪)
19
+ },
20
+
21
+ "include": ["src/**/*"], // 包含 src 下所有文件
22
+ "exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"] // 排除测试文件和产物
23
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "extends": "./tsconfig.base.json",
3
+
4
+ "compilerOptions": {
5
+ /* ========== React 与 JSX 支持 ========== */
6
+ "jsx": "react-jsx", // 关键:针对 React 17+ 的自动 JSX 转换,无需在每个文件 import React
7
+ "jsxImportSource": "react", // 指定 JSX 编译的运行时库
8
+
9
+ /* ========== 环境与目标 ========== */
10
+ "target": "ESNext", // 编译到最新的 JS 版本,适合现代浏览器
11
+ "lib": ["DOM", "DOM.Iterable", "ESNext"], // 包含浏览器 DOM 接口和最新 ES 语法
12
+ "module": "ESNext", // 使用 ESM 模块系统
13
+ "moduleResolution": "bundler", // TS 5.0+ 推荐,适配 Vite/Webpack 等打包工具的解析规则
14
+ "useDefineForClassFields": true, // 强制类字段定义符合标准 ES 规范
15
+
16
+ /* ========== 严格性与质量 ========== */
17
+ // 注意:strict 等已由 base.json 继承,此处不再重复
18
+
19
+ /* ========== 模块兼容性 ========== */
20
+ "allowJs": true, // 允许项目中存在 .js 或 .jsx 文件(适合迁移旧项目)
21
+ "allowSyntheticDefaultImports": true, // 允许没有默认导出的模块也可以用 default 导入
22
+ "isolatedModules": true, // 必须!确保每个文件可独立编译,适配 Vite 使用的 esbuild
23
+
24
+ /* ========== 构建输出设置 ========== */
25
+ "noEmit": true, // TS 只做检查,不输出 JS 文件。JS 转换由 Vite/Babel 完成
26
+ "incremental": true, // 开启增量编译,提升二次检查速度
27
+ // sourceMap 由 base.json 继承
28
+
29
+ /* ========== 路径别名 ========== */
30
+ "baseUrl": ".",
31
+ "paths": {
32
+ "@/*": ["src/*"] // 配置 @ 指向 src 目录
33
+ }
34
+ },
35
+
36
+ "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts"], // 包含的文件
37
+ "exclude": ["node_modules", "dist", "build"] // 排除的文件
38
+ }
@@ -0,0 +1,51 @@
1
+ {
2
+ "extends": "./tsconfig.base.json",
3
+
4
+ "compilerOptions": {
5
+ /* ========== Vue 浏览器环境配置 ========== */
6
+ "target": "ESNext", // 编译到最新的 JS 版本,适合现代浏览器
7
+ "lib": ["ESNext", "DOM", "DOM.Iterable"], // 包含浏览器 DOM 接口和最新 ES 语法
8
+ "module": "ESNext", // 使用 ESM 模块系统
9
+ "moduleResolution": "bundler", // TS 5.0+ 推荐,适配 Vite 等打包工具的解析规则
10
+ "useDefineForClassFields": true, // 强制类字段定义符合标准 ES 规范(Vue 3 推荐)
11
+
12
+ /* ========== JSX/TSX 处理 ========== */
13
+ "jsx": "preserve", // 保留 JSX 原样,由 Vite 插件完成转换
14
+ "jsxImportSource": "vue", // 指定 JSX 的工厂函数来源
15
+
16
+ /* ========== 模块兼容性 ========== */
17
+ "allowJs": true, // 允许项目中存在 .js 文件
18
+ "allowSyntheticDefaultImports": true, // 允许没有默认导出的模块也可以用 default 导入
19
+ "isolatedModules": true, // 必须!确保每个文件可独立编译,适配 Vite 使用的 esbuild
20
+
21
+ /* ========== 构建输出设置 ========== */
22
+ "noEmit": true, // TS 只做检查,不输出 JS 文件(Vite 负责编译)
23
+ "incremental": true, // 开启增量编译,提升二次检查速度
24
+
25
+ /* ========== Vue 类型注入 ========== */
26
+ "types": ["vite/client"], // 注入 Vite 特有的全局类型(如 import.meta.env)
27
+
28
+ /* ========== 路径别名 ========== */
29
+ "baseUrl": ".",
30
+ "paths": {
31
+ "@/*": ["./src/*"] // 配置 @ 指向 src 目录
32
+ },
33
+
34
+ /* ========== 代码质量检查 ========== */
35
+ "noUnusedLocals": true, // 定义的变量若未使用则报错(保持代码整洁)
36
+ "noUnusedParameters": true, // 函数参数若未使用则报错
37
+ "noFallthroughCasesInSwitch": true // 防止 switch 语句忘记写 break 导致穿透
38
+ },
39
+
40
+ /* ========== 包含与排除 ========== */
41
+ "include": [
42
+ "src/**/*.ts", // 检查 src 下所有的 .ts 文件
43
+ "src/**/*.d.ts", // 检查 src 下所有的类型声明文件
44
+ "src/**/*.tsx", // 检查 src 下所有的 .tsx 文件
45
+ "src/**/*.vue" // 关键!检查 src 下所有的 .vue 文件(Vue 插件会处理)
46
+ ],
47
+ "exclude": [
48
+ "node_modules", // 排除依赖库
49
+ "dist" // 排除打包产物
50
+ ]
51
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "extends": "./tsconfig.base.json",
3
+
4
+ "compilerOptions": {
5
+ /* ========== 环境与目标 - 针对浏览器 ========== */
6
+ "target": "ES2020", // 通常编译到较新的版本,由使用者的打包工具决定是否进一步降级
7
+ "useDefineForClassFields": true, // 使用标准的 ECMAScript 类字段定义方式(Vue 3/现代 JS 推荐)
8
+ "module": "ESNext", // 必须使用 ESM 模块,方便使用者进行 Tree-shaking(摇树优化)
9
+ "lib": ["ESNext", "DOM", "DOM.Iterable"], // 核心:告诉 TS 运行在浏览器环境,可以使用 window, document 等
10
+ "moduleResolution": "bundler", // 现代库开发的标准,模拟 Vite/Webpack 等打包工具的寻址逻辑
11
+
12
+ /* ========== 库专用的产物配置 ========== */
13
+ "declaration": true, // 必须!生成 .d.ts 类型声明文件,别人引用你时才有代码提示
14
+ "declarationMap": true, // 可选:生成类型映射文件,允许使用者"跳转到定义"时直接定位到你的 TS 源码
15
+ "emitDeclarationOnly": false, // 如果只让 tsc 生成类型(JS 交给 Vite 处理),则设为 true
16
+ "sourceMap": true, // 生成 .map 文件,方便在浏览器控制台调试源码
17
+ "outDir": "./dist", // 编译产物的存放路径
18
+
19
+ /* ========== 严格检查 - 保证库的质量 ========== */
20
+ // 注意:strict 等已由 base.json 继承,此处不再重复
21
+ // "skipLibCheck": true 已由 base.json 继承
22
+
23
+ /* ========== 模块与兼容性 ========== */
24
+ "esModuleInterop": true, // 允许像 import React from 'react' 这样导入 CommonJS 模块
25
+ "isolatedModules": true, // 确保每个文件都能独立编译(Vite/esbuild 的硬性要求)
26
+
27
+ /* ========== 路径别名 ========== */
28
+ "baseUrl": ".",
29
+ "paths": {
30
+ "@/*": ["src/*"] // 设置库内部的路径快捷方式
31
+ }
32
+ },
33
+
34
+ "include": ["src/**/*.ts"], // 只编译 src 目录下的源码
35
+ "exclude": [ // 排除不需要打包的文件
36
+ "node_modules",
37
+ "dist",
38
+ "**/*.test.ts",
39
+ "**/*.spec.ts"
40
+ ]
41
+ }