fe-stack 0.0.1
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 +146 -0
- package/biome.json +83 -0
- package/package.json +62 -0
- package/prettier.json +18 -0
- package/tailwind.config.js +11 -0
- package/tsconfig.app.json +15 -0
- package/tsconfig.node.json +22 -0
- package/vite.config.base.js +74 -0
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# fe-stack
|
|
2
|
+
|
|
3
|
+
一个包含 Vite、Tailwind、Biome、Prettier 和 TypeScript 配置的共享包,可以在多个项目中复用。
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## 安装方法
|
|
7
|
+
|
|
8
|
+
在项目中安装:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pnpm add -D fe-stack
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 使用方法
|
|
15
|
+
|
|
16
|
+
### 1. Biome 配置
|
|
17
|
+
|
|
18
|
+
在项目中创建 `biome.json` 继承:
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"extends": ["fe-stack/biome.json"]
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### 2. Prettier 配置
|
|
26
|
+
|
|
27
|
+
在项目根目录创建 `.prettierrc.json`:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
"fe-stack/prettier.json"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
或者:
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"extends": "fe-stack/prettier.json"
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 3. Tailwind 配置
|
|
41
|
+
|
|
42
|
+
在项目中创建 `tailwind.config.js`:
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
import baseConfig from 'fe-stack/tailwind.config.js';
|
|
46
|
+
|
|
47
|
+
export default {
|
|
48
|
+
...baseConfig,
|
|
49
|
+
// 项目特定的覆盖配置
|
|
50
|
+
theme: {
|
|
51
|
+
extend: {
|
|
52
|
+
...baseConfig.theme?.extend,
|
|
53
|
+
// 你的自定义主题
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 4. TypeScript 配置
|
|
60
|
+
|
|
61
|
+
**tsconfig.json**(Vue 应用):
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"files": [],
|
|
65
|
+
"references": [
|
|
66
|
+
{ "path": "./tsconfig.app.json" },
|
|
67
|
+
{ "path": "./tsconfig.node.json" }
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**tsconfig.app.json**:
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"extends": "fe-stack/tsconfig.app.json",
|
|
76
|
+
"compilerOptions": {
|
|
77
|
+
"baseUrl": ".",
|
|
78
|
+
"paths": {
|
|
79
|
+
"@/*": ["./src/*"]
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"]
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**tsconfig.node.json**:
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"extends": "fe-stack/tsconfig.node.json",
|
|
90
|
+
"include": ["vite.config.*"]
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 5. Vite 配置
|
|
95
|
+
|
|
96
|
+
#### Vue 应用模式
|
|
97
|
+
|
|
98
|
+
在项目中创建 `vite.config.ts`:
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { defineConfig } from 'vite';
|
|
102
|
+
import { createBaseConfig } from 'fe-stack/vite.config.base.js';
|
|
103
|
+
|
|
104
|
+
const baseConfig = createBaseConfig(import.meta.dirname, { mode: 'app' });
|
|
105
|
+
|
|
106
|
+
export default defineConfig({
|
|
107
|
+
...baseConfig,
|
|
108
|
+
// 项目特定配置
|
|
109
|
+
server: {
|
|
110
|
+
port: 5173,
|
|
111
|
+
proxy: {
|
|
112
|
+
'/api': {
|
|
113
|
+
target: 'http://your-api-server',
|
|
114
|
+
changeOrigin: true,
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
#### Lib 打包模式
|
|
122
|
+
|
|
123
|
+
用于打包纯 TypeScript 库:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import { defineConfig } from 'vite';
|
|
127
|
+
import { createBaseConfig } from 'fe-stack/vite.config.base.js';
|
|
128
|
+
|
|
129
|
+
const baseConfig = createBaseConfig(import.meta.dirname, {
|
|
130
|
+
mode: 'lib',
|
|
131
|
+
libOptions: {
|
|
132
|
+
lib: {
|
|
133
|
+
name: 'MyLib', // UMD 全局变量名
|
|
134
|
+
},
|
|
135
|
+
dtsExclude: ['src/**/*.test.ts'], // 排除测试文件
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
export default defineConfig(baseConfig);
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**特性:**
|
|
143
|
+
- ✅ 自动配置 `vite-plugin-dts` 生成类型文件
|
|
144
|
+
- ✅ 自动合并所有类型到单个 `.d.ts` 文件
|
|
145
|
+
- ✅ 默认打包为 ESM 格式
|
|
146
|
+
- ✅ entry 默认为 `src/index.ts`
|
package/biome.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.2.6/schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": true,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": true
|
|
7
|
+
},
|
|
8
|
+
"files": {
|
|
9
|
+
"ignoreUnknown": false,
|
|
10
|
+
"experimentalScannerIgnores": ["node_modules", "build", "dist", "public"]
|
|
11
|
+
},
|
|
12
|
+
"assist": {
|
|
13
|
+
"actions": {
|
|
14
|
+
"source": {
|
|
15
|
+
"organizeImports": {
|
|
16
|
+
"level": "on",
|
|
17
|
+
"options": {
|
|
18
|
+
"groups": [":URL:", ":NODE:"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"formatter": {
|
|
25
|
+
"enabled": true,
|
|
26
|
+
"lineWidth": 80,
|
|
27
|
+
"indentStyle": "space",
|
|
28
|
+
"indentWidth": 2
|
|
29
|
+
},
|
|
30
|
+
"javascript": {
|
|
31
|
+
"formatter": {
|
|
32
|
+
"quoteStyle": "single"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"linter": {
|
|
36
|
+
"enabled": true,
|
|
37
|
+
"domains": {
|
|
38
|
+
"vue": "all"
|
|
39
|
+
},
|
|
40
|
+
"rules": {
|
|
41
|
+
"recommended": true,
|
|
42
|
+
"suspicious": {
|
|
43
|
+
"noExplicitAny": "off",
|
|
44
|
+
"noUnknownAtRules": "off"
|
|
45
|
+
},
|
|
46
|
+
"performance": {
|
|
47
|
+
"noDynamicNamespaceImportAccess": "off"
|
|
48
|
+
},
|
|
49
|
+
"style": {
|
|
50
|
+
"noNonNullAssertion": "off"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"overrides": [
|
|
55
|
+
{
|
|
56
|
+
"includes": [".vscode/**"],
|
|
57
|
+
"json": {
|
|
58
|
+
"parser": {
|
|
59
|
+
"allowComments": true,
|
|
60
|
+
"allowTrailingCommas": true
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"includes": ["**/*.vue"],
|
|
66
|
+
"formatter": {
|
|
67
|
+
"enabled": false
|
|
68
|
+
},
|
|
69
|
+
"linter": {
|
|
70
|
+
"rules": {
|
|
71
|
+
"style": {
|
|
72
|
+
"useConst": "off",
|
|
73
|
+
"useImportType": "off"
|
|
74
|
+
},
|
|
75
|
+
"correctness": {
|
|
76
|
+
"noUnusedVariables": "off",
|
|
77
|
+
"noUnusedImports": "off"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fe-stack",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "共享的配置文件集合,用于 Vite、Tailwind、Biome、Prettier 和 TypeScript",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./vite.config.base.js": "./vite.config.base.js",
|
|
8
|
+
"./tsconfig.*.json": "./tsconfig.*.json",
|
|
9
|
+
"./biome.json": "./biome.json",
|
|
10
|
+
"./prettier.json": "./prettier.json",
|
|
11
|
+
"./tailwind.config.js": "./tailwind.config.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"biome.json",
|
|
15
|
+
"prettier.json",
|
|
16
|
+
"tailwind.config.js",
|
|
17
|
+
"tsconfig.app.json",
|
|
18
|
+
"tsconfig.node.json",
|
|
19
|
+
"vite.config.base.js",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"config",
|
|
24
|
+
"vite",
|
|
25
|
+
"tailwind",
|
|
26
|
+
"biome",
|
|
27
|
+
"prettier",
|
|
28
|
+
"typescript",
|
|
29
|
+
"vue",
|
|
30
|
+
"shared-config"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"dev": "pnpm --filter playground dev",
|
|
34
|
+
"dev:lib": "pnpm --filter playground-lib dev",
|
|
35
|
+
"test:lib": "pnpm --filter playground-lib test",
|
|
36
|
+
"build:lib": "pnpm --filter playground-lib build",
|
|
37
|
+
"build:playground": "pnpm --filter playground build",
|
|
38
|
+
"preview": "pnpm --filter playground preview",
|
|
39
|
+
"prepublishOnly": "pnpm pack --dry-run"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@tailwindcss/vite": "^4.1.18",
|
|
43
|
+
"@types/node": "^22.10.5",
|
|
44
|
+
"@vitejs/plugin-vue": "^6.0.3",
|
|
45
|
+
"@vue/tsconfig": "^0.7.0",
|
|
46
|
+
"unplugin-auto-import": "^20.3.0",
|
|
47
|
+
"unplugin-vue-components": "^30.0.0",
|
|
48
|
+
"unplugin-vue-router": "^0.19.2",
|
|
49
|
+
"vite-plugin-dts": "^4.5.4"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@biomejs/biome": "^2.2.6",
|
|
53
|
+
"prettier": "^3.7.4",
|
|
54
|
+
"tailwindcss": "^4.1.18",
|
|
55
|
+
"typescript": "~5.9.3",
|
|
56
|
+
"vite": "^7.3.1"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=18.0.0",
|
|
60
|
+
"pnpm": ">=8.0.0"
|
|
61
|
+
}
|
|
62
|
+
}
|
package/prettier.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"semi": true,
|
|
3
|
+
"singleQuote": true,
|
|
4
|
+
"printWidth": 80,
|
|
5
|
+
"tabWidth": 2,
|
|
6
|
+
"trailingComma": "all",
|
|
7
|
+
"arrowParens": "always",
|
|
8
|
+
"endOfLine": "lf",
|
|
9
|
+
"overrides": [
|
|
10
|
+
{
|
|
11
|
+
"files": "*.vue",
|
|
12
|
+
"options": {
|
|
13
|
+
"parser": "vue",
|
|
14
|
+
"vueIndentScriptAndStyle": false
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@vue/tsconfig/tsconfig.dom.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
|
5
|
+
"types": ["vite/client", "unplugin-vue-router/client"],
|
|
6
|
+
"strict": true,
|
|
7
|
+
"noUnusedLocals": true,
|
|
8
|
+
"noUnusedParameters": true,
|
|
9
|
+
"erasableSyntaxOnly": true,
|
|
10
|
+
"noFallthroughCasesInSwitch": true,
|
|
11
|
+
"noUncheckedSideEffectImports": true,
|
|
12
|
+
"module": "ESNext",
|
|
13
|
+
"moduleResolution": "Bundler"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
|
4
|
+
"target": "ES2023",
|
|
5
|
+
"lib": ["ES2023"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"moduleResolution": "bundler",
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
11
|
+
"verbatimModuleSyntax": true,
|
|
12
|
+
"moduleDetection": "force",
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"strict": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"noUnusedParameters": true,
|
|
17
|
+
"erasableSyntaxOnly": true,
|
|
18
|
+
"noFallthroughCasesInSwitch": true,
|
|
19
|
+
"noUncheckedSideEffectImports": true,
|
|
20
|
+
"customConditions": ["node"]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import tailwindcss from '@tailwindcss/vite';
|
|
3
|
+
import vue from '@vitejs/plugin-vue';
|
|
4
|
+
import AutoImport from 'unplugin-auto-import/vite';
|
|
5
|
+
import Components from 'unplugin-vue-components/vite';
|
|
6
|
+
import VueRouter from 'unplugin-vue-router/vite';
|
|
7
|
+
import dts from 'vite-plugin-dts';
|
|
8
|
+
|
|
9
|
+
export function createBaseConfig(dirname, options = {}) {
|
|
10
|
+
const { mode = 'app', libOptions = {} } = options;
|
|
11
|
+
|
|
12
|
+
const baseConfig = {
|
|
13
|
+
resolve: {
|
|
14
|
+
alias: {
|
|
15
|
+
'@': path.resolve(dirname, './src'),
|
|
16
|
+
},
|
|
17
|
+
extensions: [
|
|
18
|
+
'.mjs',
|
|
19
|
+
'.js',
|
|
20
|
+
'.mts',
|
|
21
|
+
'.ts',
|
|
22
|
+
'.jsx',
|
|
23
|
+
'.tsx',
|
|
24
|
+
'.json',
|
|
25
|
+
'.vue',
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
plugins: [],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// App mode: 包含 Vue 全家桶
|
|
32
|
+
if (mode === 'app') {
|
|
33
|
+
baseConfig.plugins.push(
|
|
34
|
+
VueRouter({
|
|
35
|
+
dts: './src/typed-router.d.ts',
|
|
36
|
+
}),
|
|
37
|
+
vue(),
|
|
38
|
+
tailwindcss(),
|
|
39
|
+
AutoImport({
|
|
40
|
+
imports: ['vue', 'vue-router'],
|
|
41
|
+
dts: './src/auto-imports.d.ts',
|
|
42
|
+
}),
|
|
43
|
+
Components({
|
|
44
|
+
directoryAsNamespace: true,
|
|
45
|
+
dts: './src/components.d.ts',
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Lib mode: 纯 TypeScript,用于打包库
|
|
51
|
+
if (mode === 'lib') {
|
|
52
|
+
// 添加 lib 构建配置
|
|
53
|
+
baseConfig.build = {
|
|
54
|
+
lib: {
|
|
55
|
+
entry: path.resolve(dirname, 'src/index.ts'),
|
|
56
|
+
formats: ['es'],
|
|
57
|
+
fileName: 'index',
|
|
58
|
+
...libOptions.lib,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// 添加 dts 插件
|
|
63
|
+
baseConfig.plugins.push(
|
|
64
|
+
dts({
|
|
65
|
+
include: ['src/**/*.ts'],
|
|
66
|
+
exclude: libOptions.dtsExclude || [],
|
|
67
|
+
rollupTypes: true,
|
|
68
|
+
...libOptions.dts,
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return baseConfig;
|
|
74
|
+
}
|