fe-stack 0.0.1 → 0.0.3

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 CHANGED
@@ -95,23 +95,18 @@ export default {
95
95
 
96
96
  #### Vue 应用模式
97
97
 
98
- 在项目中创建 `vite.config.ts`:
99
-
100
98
  ```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,
99
+ import { createBaseConfig } from 'fe-stack/vite.config.base';
100
+
101
+ export default createBaseConfig(import.meta.dirname, {
102
+ viteConfig: {
103
+ server: {
104
+ port: 5173,
105
+ proxy: {
106
+ '/api': {
107
+ target: 'http://your-api-server',
108
+ changeOrigin: true,
109
+ }
115
110
  }
116
111
  }
117
112
  }
@@ -120,27 +115,26 @@ export default defineConfig({
120
115
 
121
116
  #### Lib 打包模式
122
117
 
123
- 用于打包纯 TypeScript 库:
124
-
125
118
  ```typescript
126
- import { defineConfig } from 'vite';
127
- import { createBaseConfig } from 'fe-stack/vite.config.base.js';
119
+ import { createBaseConfig } from 'fe-stack/vite.config.base';
128
120
 
129
- const baseConfig = createBaseConfig(import.meta.dirname, {
121
+ export default createBaseConfig(import.meta.dirname, {
130
122
  mode: 'lib',
131
- libOptions: {
132
- lib: {
133
- name: 'MyLib', // UMD 全局变量名
123
+ viteConfig: {
124
+ build: {
125
+ lib: {
126
+ entry: './src/index.ts',
127
+ name: 'MyLib',
128
+ fileName: 'index',
129
+ },
134
130
  },
135
- dtsExclude: ['src/**/*.test.ts'], // 排除测试文件
136
131
  },
137
132
  });
138
-
139
- export default defineConfig(baseConfig);
140
133
  ```
141
134
 
142
135
  **特性:**
143
- - ✅ 自动配置 `vite-plugin-dts` 生成类型文件
144
- - ✅ 自动合并所有类型到单个 `.d.ts` 文件
136
+ - ✅ 完整的 TypeScript 类型支持
137
+ - ✅ 使用 `mergeConfig` 优雅合并配置
138
+ - ✅ lib 模式自动配置 `vite-plugin-dts`
145
139
  - ✅ 默认打包为 ESM 格式
146
- - ✅ entry 默认为 `src/index.ts`
140
+ - ✅ 所有配置通过 `viteConfig` 统一管理,简单直观
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "fe-stack",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "共享的配置文件集合,用于 Vite、Tailwind、Biome、Prettier 和 TypeScript",
5
5
  "type": "module",
6
6
  "exports": {
7
- "./vite.config.base.js": "./vite.config.base.js",
7
+ "./vite.config.base": {
8
+ "types": "./vite.config.base.ts",
9
+ "import": "./vite.config.base.ts"
10
+ },
8
11
  "./tsconfig.*.json": "./tsconfig.*.json",
9
12
  "./biome.json": "./biome.json",
10
13
  "./prettier.json": "./prettier.json",
@@ -16,7 +19,7 @@
16
19
  "tailwind.config.js",
17
20
  "tsconfig.app.json",
18
21
  "tsconfig.node.json",
19
- "vite.config.base.js",
22
+ "vite.config.base.ts",
20
23
  "README.md"
21
24
  ],
22
25
  "keywords": [
package/tsconfig.app.json CHANGED
@@ -9,6 +9,7 @@
9
9
  "erasableSyntaxOnly": true,
10
10
  "noFallthroughCasesInSwitch": true,
11
11
  "noUncheckedSideEffectImports": true,
12
+ "verbatimModuleSyntax": false,
12
13
  "module": "ESNext",
13
14
  "moduleResolution": "Bundler"
14
15
  }
@@ -4,12 +4,22 @@ import vue from '@vitejs/plugin-vue';
4
4
  import AutoImport from 'unplugin-auto-import/vite';
5
5
  import Components from 'unplugin-vue-components/vite';
6
6
  import VueRouter from 'unplugin-vue-router/vite';
7
+ import type { UserConfig } from 'vite';
8
+ import { defineConfig, mergeConfig } from 'vite';
7
9
  import dts from 'vite-plugin-dts';
8
10
 
9
- export function createBaseConfig(dirname, options = {}) {
10
- const { mode = 'app', libOptions = {} } = options;
11
+ export interface CreateBaseConfigOptions {
12
+ mode?: 'app' | 'lib';
13
+ viteConfig?: UserConfig;
14
+ }
15
+
16
+ export function createBaseConfig(
17
+ dirname: string,
18
+ options: CreateBaseConfigOptions = {},
19
+ ) {
20
+ const { mode = 'app', viteConfig = {} } = options;
11
21
 
12
- const baseConfig = {
22
+ const baseConfig: UserConfig = {
13
23
  resolve: {
14
24
  alias: {
15
25
  '@': path.resolve(dirname, './src'),
@@ -30,7 +40,7 @@ export function createBaseConfig(dirname, options = {}) {
30
40
 
31
41
  // App mode: 包含 Vue 全家桶
32
42
  if (mode === 'app') {
33
- baseConfig.plugins.push(
43
+ baseConfig.plugins!.push(
34
44
  VueRouter({
35
45
  dts: './src/typed-router.d.ts',
36
46
  }),
@@ -47,28 +57,26 @@ export function createBaseConfig(dirname, options = {}) {
47
57
  );
48
58
  }
49
59
 
50
- // Lib mode: 纯 TypeScript,用于打包库
60
+ // Lib mode: 提供默认配置
51
61
  if (mode === 'lib') {
52
- // 添加 lib 构建配置
53
62
  baseConfig.build = {
54
63
  lib: {
55
64
  entry: path.resolve(dirname, 'src/index.ts'),
56
65
  formats: ['es'],
57
66
  fileName: 'index',
58
- ...libOptions.lib,
59
67
  },
60
68
  };
61
69
 
62
- // 添加 dts 插件
63
- baseConfig.plugins.push(
70
+ // 默认添加 dts 插件
71
+ baseConfig.plugins!.push(
64
72
  dts({
65
73
  include: ['src/**/*.ts'],
66
- exclude: libOptions.dtsExclude || [],
74
+ root: dirname,
67
75
  rollupTypes: true,
68
- ...libOptions.dts,
69
76
  }),
70
77
  );
71
78
  }
72
79
 
73
- return baseConfig;
80
+ // 使用 mergeConfig 合并用户自定义配置
81
+ return defineConfig(mergeConfig(baseConfig, viteConfig));
74
82
  }