fe-stack 0.0.3 → 0.0.5
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 +6 -1
- package/package.json +5 -4
- package/vite.config.base.d.ts +32 -0
- package/{vite.config.base.ts → vite.config.base.js} +30 -14
package/README.md
CHANGED
|
@@ -120,6 +120,11 @@ import { createBaseConfig } from 'fe-stack/vite.config.base';
|
|
|
120
120
|
|
|
121
121
|
export default createBaseConfig(import.meta.dirname, {
|
|
122
122
|
mode: 'lib',
|
|
123
|
+
dtsConfig: {
|
|
124
|
+
// 自定义 vite-plugin-dts 配置
|
|
125
|
+
exclude: ['**/*.test.ts', '**/*.spec.ts'],
|
|
126
|
+
insertTypesEntry: true,
|
|
127
|
+
},
|
|
123
128
|
viteConfig: {
|
|
124
129
|
build: {
|
|
125
130
|
lib: {
|
|
@@ -135,6 +140,6 @@ export default createBaseConfig(import.meta.dirname, {
|
|
|
135
140
|
**特性:**
|
|
136
141
|
- ✅ 完整的 TypeScript 类型支持
|
|
137
142
|
- ✅ 使用 `mergeConfig` 优雅合并配置
|
|
143
|
+
- ✅ `dtsConfig` 直接配置 dts 插件选项
|
|
138
144
|
- ✅ lib 模式自动配置 `vite-plugin-dts`
|
|
139
145
|
- ✅ 默认打包为 ESM 格式
|
|
140
|
-
- ✅ 所有配置通过 `viteConfig` 统一管理,简单直观
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fe-stack",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "共享的配置文件集合,用于 Vite、Tailwind、Biome、Prettier 和 TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./vite.config.base": {
|
|
8
|
-
"types": "./vite.config.base.ts",
|
|
9
|
-
"import": "./vite.config.base.
|
|
8
|
+
"types": "./vite.config.base.d.ts",
|
|
9
|
+
"import": "./vite.config.base.js"
|
|
10
10
|
},
|
|
11
11
|
"./tsconfig.*.json": "./tsconfig.*.json",
|
|
12
12
|
"./biome.json": "./biome.json",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"tailwind.config.js",
|
|
20
20
|
"tsconfig.app.json",
|
|
21
21
|
"tsconfig.node.json",
|
|
22
|
-
"vite.config.base.
|
|
22
|
+
"vite.config.base.js",
|
|
23
|
+
"vite.config.base.d.ts",
|
|
23
24
|
"README.md"
|
|
24
25
|
],
|
|
25
26
|
"keywords": [
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { UserConfig } from 'vite';
|
|
2
|
+
import type { PluginOptions as DtsPluginOptions } from 'vite-plugin-dts';
|
|
3
|
+
|
|
4
|
+
export interface CreateBaseConfigOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 构建模式
|
|
7
|
+
* - 'app': Vue 应用模式,包含 Vue Router、Auto Import 等
|
|
8
|
+
* - 'lib': 库打包模式,配置 vite-plugin-dts
|
|
9
|
+
*/
|
|
10
|
+
mode?: 'app' | 'lib';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* vite-plugin-dts 配置(仅 lib 模式)
|
|
14
|
+
* 会与默认配置合并,可以覆盖 include、exclude 等选项
|
|
15
|
+
*/
|
|
16
|
+
dtsConfig?: Partial<DtsPluginOptions>;
|
|
17
|
+
/**
|
|
18
|
+
* 额外的 Vite 配置,会与基础配置合并
|
|
19
|
+
*/
|
|
20
|
+
viteConfig?: UserConfig;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 创建基础 Vite 配置
|
|
25
|
+
* @param dirname - 项目根目录路径(通常使用 import.meta.dirname)
|
|
26
|
+
* @param options - 配置选项
|
|
27
|
+
* @returns Vite 配置
|
|
28
|
+
*/
|
|
29
|
+
export function createBaseConfig(
|
|
30
|
+
dirname: string,
|
|
31
|
+
options?: CreateBaseConfigOptions,
|
|
32
|
+
): import('vite').UserConfigExport;
|
|
@@ -4,22 +4,29 @@ 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
7
|
import { defineConfig, mergeConfig } from 'vite';
|
|
9
8
|
import dts from 'vite-plugin-dts';
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {import('vite').UserConfig} UserConfig
|
|
12
|
+
* @typedef {import('vite-plugin-dts').PluginOptions} DtsPluginOptions
|
|
13
|
+
* @typedef {Object} CreateBaseConfigOptions
|
|
14
|
+
* @property {'app' | 'lib'} [mode] - 构建模式:'app' 为 Vue 应用,'lib' 为库打包
|
|
15
|
+
* @property {Partial<DtsPluginOptions>} [dtsConfig] - vite-plugin-dts 配置(仅 lib 模式),会与默认配置合并
|
|
16
|
+
* @property {UserConfig} [viteConfig] - 额外的 Vite 配置,会与基础配置合并
|
|
17
|
+
*/
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
/**
|
|
20
|
+
* 创建基础 Vite 配置
|
|
21
|
+
* @param {string} dirname - 项目根目录路径
|
|
22
|
+
* @param {CreateBaseConfigOptions} [options] - 配置选项
|
|
23
|
+
* @returns {import('vite').UserConfigExport} Vite 配置
|
|
24
|
+
*/
|
|
25
|
+
export function createBaseConfig(dirname, options = {}) {
|
|
26
|
+
const { mode = 'app', dtsConfig = {}, viteConfig = {} } = options;
|
|
21
27
|
|
|
22
|
-
|
|
28
|
+
/** @type {UserConfig} */
|
|
29
|
+
const baseConfig = {
|
|
23
30
|
resolve: {
|
|
24
31
|
alias: {
|
|
25
32
|
'@': path.resolve(dirname, './src'),
|
|
@@ -36,11 +43,19 @@ export function createBaseConfig(
|
|
|
36
43
|
],
|
|
37
44
|
},
|
|
38
45
|
plugins: [],
|
|
46
|
+
worker: {
|
|
47
|
+
format: 'es',
|
|
48
|
+
rollupOptions: {
|
|
49
|
+
output: {
|
|
50
|
+
format: 'es',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
39
54
|
};
|
|
40
55
|
|
|
41
56
|
// App mode: 包含 Vue 全家桶
|
|
42
57
|
if (mode === 'app') {
|
|
43
|
-
baseConfig.plugins
|
|
58
|
+
baseConfig.plugins.push(
|
|
44
59
|
VueRouter({
|
|
45
60
|
dts: './src/typed-router.d.ts',
|
|
46
61
|
}),
|
|
@@ -67,12 +82,13 @@ export function createBaseConfig(
|
|
|
67
82
|
},
|
|
68
83
|
};
|
|
69
84
|
|
|
70
|
-
//
|
|
71
|
-
baseConfig.plugins
|
|
85
|
+
// 添加 dts 插件,用户配置会覆盖默认配置
|
|
86
|
+
baseConfig.plugins.push(
|
|
72
87
|
dts({
|
|
73
88
|
include: ['src/**/*.ts'],
|
|
74
89
|
root: dirname,
|
|
75
90
|
rollupTypes: true,
|
|
91
|
+
...dtsConfig,
|
|
76
92
|
}),
|
|
77
93
|
);
|
|
78
94
|
}
|