@moluoxixi/vite-config 0.0.27 → 0.0.30
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 +1 -1
- package/es/index.mjs +182 -20
- package/es/src/_types/index.d.ts +101 -1
- package/es/src/_utils/detectFramework.d.ts +42 -0
- package/es/src/_utils/getEnv.d.ts +15 -0
- package/es/src/_utils/index.d.ts +1 -0
- package/lib/index.cjs +1218 -0
- package/lib/index.d.ts +4 -0
- package/lib/src/_types/index.d.ts +189 -0
- package/lib/src/_utils/detectFramework.d.ts +42 -0
- package/lib/src/_utils/getEnv.d.ts +22 -0
- package/lib/src/_utils/index.d.ts +2 -0
- package/lib/src/constants/index.d.ts +1 -0
- package/lib/src/index.d.ts +6 -0
- package/lib/src/plugins/addScopedAndReplacePrefix.d.ts +10 -0
- package/lib/src/plugins/vitePluginQiankunStyle.d.ts +10 -0
- package/package.json +18 -6
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ export default viteConfig(({ mode }) => {
|
|
|
16
16
|
return {
|
|
17
17
|
rootPath: path.resolve(),
|
|
18
18
|
mode: {
|
|
19
|
-
base: {
|
|
19
|
+
base: { VITE_APP_TITLE: viteEnv.VITE_APP_TITLE, VITE_APP_CODE: viteEnv.VITE_APP_CODE, VITE_AUTO_ROUTES: true },
|
|
20
20
|
development: { VITE_DEVTOOLS: true },
|
|
21
21
|
production: {},
|
|
22
22
|
},
|
package/es/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import "vue";
|
|
5
4
|
import fs from "node:fs";
|
|
6
5
|
import path from "node:path";
|
|
7
6
|
import process$1 from "node:process";
|
|
7
|
+
import "vue";
|
|
8
8
|
import "dotenv";
|
|
9
9
|
import tailwindcss from "@tailwindcss/postcss";
|
|
10
10
|
import autoprefixer from "autoprefixer";
|
|
@@ -46,6 +46,80 @@ function deepMerge(target, source) {
|
|
|
46
46
|
return acc;
|
|
47
47
|
}, { ...target });
|
|
48
48
|
}
|
|
49
|
+
function validateMutuallyExclusive(values, defaultKey) {
|
|
50
|
+
const keys = Object.keys(values);
|
|
51
|
+
const enabledKeys = [];
|
|
52
|
+
for (const key of keys) {
|
|
53
|
+
if (values[key] === true) {
|
|
54
|
+
enabledKeys.push(key);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (enabledKeys.length > 1) {
|
|
58
|
+
const keysStr = enabledKeys.join("、");
|
|
59
|
+
const allKeysStr = keys.join("、");
|
|
60
|
+
const selectedKey = enabledKeys.includes(defaultKey) ? defaultKey : enabledKeys[0];
|
|
61
|
+
console.warn(
|
|
62
|
+
`[validateMutuallyExclusive] ${allKeysStr} 只能启用一个,但当前启用了:${keysStr}。已自动选择:${String(selectedKey)}`
|
|
63
|
+
);
|
|
64
|
+
const result2 = {};
|
|
65
|
+
for (const key of keys) {
|
|
66
|
+
result2[key] = key === selectedKey;
|
|
67
|
+
}
|
|
68
|
+
return result2;
|
|
69
|
+
}
|
|
70
|
+
const hasEnabledKey = enabledKeys.length > 0;
|
|
71
|
+
const result = {};
|
|
72
|
+
for (const key of keys) {
|
|
73
|
+
if (!hasEnabledKey && defaultKey && key === defaultKey) {
|
|
74
|
+
result[key] = true;
|
|
75
|
+
} else {
|
|
76
|
+
result[key] = values[key] ?? false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
function detectFramework(config, rootDir) {
|
|
82
|
+
const root = rootDir || process$1.cwd();
|
|
83
|
+
const packageJsonPath = path.resolve(root, "package.json");
|
|
84
|
+
let vue = config.vue;
|
|
85
|
+
let react = config.react;
|
|
86
|
+
let vitepress = config.vitepress;
|
|
87
|
+
const hasExplicitFramework = vue === true || react === true || vitepress === true;
|
|
88
|
+
if (!hasExplicitFramework) {
|
|
89
|
+
let dependencies = {};
|
|
90
|
+
let devDependencies = {};
|
|
91
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
92
|
+
try {
|
|
93
|
+
const packageJsonContent = fs.readFileSync(packageJsonPath, "utf-8");
|
|
94
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
95
|
+
dependencies = packageJson.dependencies || {};
|
|
96
|
+
devDependencies = packageJson.devDependencies || {};
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.warn(`无法读取 package.json: ${packageJsonPath}`, error);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (vue === void 0) {
|
|
102
|
+
if (dependencies.vue || devDependencies.vue) {
|
|
103
|
+
vue = true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (react === void 0 && vue !== true) {
|
|
107
|
+
if (dependencies.react || devDependencies.react) {
|
|
108
|
+
react = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (vitepress === void 0 && vue !== true && react !== true) {
|
|
112
|
+
if (dependencies.vitepress || devDependencies.vitepress) {
|
|
113
|
+
vitepress = true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
vue: vue ?? false,
|
|
119
|
+
react: react ?? false,
|
|
120
|
+
vitepress: vitepress ?? false
|
|
121
|
+
};
|
|
122
|
+
}
|
|
49
123
|
function changeHtmlClassPrefix(htmlString = "", oldPrefix = "", newPrefix = "") {
|
|
50
124
|
const regex = new RegExp(
|
|
51
125
|
`(class|style)\\s*:\\s*((["']((${oldPrefix}\\b)-).*["'])|((_normalizeClass|_normalizeStyle)\\(.*(${oldPrefix}\\b)-.*\\)))`,
|
|
@@ -99,12 +173,9 @@ function addScopedAndReplacePrefixPlugin({
|
|
|
99
173
|
}
|
|
100
174
|
async function getViteConfig(Config, params) {
|
|
101
175
|
const configResult = typeof Config === "function" ? Config(params) : Config;
|
|
102
|
-
if (!configResult || !configResult.rootPath) {
|
|
103
|
-
throw new Error("rootPath is required in ViteConfig");
|
|
104
|
-
}
|
|
105
176
|
const config = configResult;
|
|
106
177
|
const { mode = "base" } = params || {};
|
|
107
|
-
const rootPath = config.rootPath;
|
|
178
|
+
const rootPath = config.rootPath || process.cwd();
|
|
108
179
|
const modeConfig = config.mode || {};
|
|
109
180
|
const baseConfig = modeConfig.base || {};
|
|
110
181
|
const currentModeConfig = modeConfig[mode] || {};
|
|
@@ -128,13 +199,24 @@ async function getViteConfig(Config, params) {
|
|
|
128
199
|
qiankun = config.qiankun,
|
|
129
200
|
namespace = config.namespace,
|
|
130
201
|
dropConsole = config.dropConsole,
|
|
131
|
-
vue = config.vue
|
|
132
|
-
react = config.react,
|
|
133
|
-
vitepress = config.vitepress
|
|
202
|
+
vue: vueRaw = config.vue,
|
|
203
|
+
react: reactRaw = config.react,
|
|
204
|
+
vitepress: vitepressRaw = config.vitepress
|
|
134
205
|
} = viteEnv;
|
|
206
|
+
const frameworkResult = detectFramework(
|
|
207
|
+
{
|
|
208
|
+
vue: vueRaw,
|
|
209
|
+
react: reactRaw,
|
|
210
|
+
vitepress: vitepressRaw
|
|
211
|
+
},
|
|
212
|
+
rootPath
|
|
213
|
+
);
|
|
214
|
+
const { vue, react, vitepress } = validateMutuallyExclusive(
|
|
215
|
+
frameworkResult,
|
|
216
|
+
"vue"
|
|
217
|
+
);
|
|
135
218
|
const appTitle = config.appTitle;
|
|
136
219
|
const appCode = config.appCode;
|
|
137
|
-
const isOnlyVue = !vitepress && !react && vue;
|
|
138
220
|
const isVueOrVitepress = vue || vitepress;
|
|
139
221
|
const envSystemCode = isDev && !qiankunDevMode ? "el" : namespace ?? appCode;
|
|
140
222
|
const plugins = [
|
|
@@ -146,21 +228,32 @@ async function getViteConfig(Config, params) {
|
|
|
146
228
|
}
|
|
147
229
|
})
|
|
148
230
|
];
|
|
149
|
-
if (
|
|
231
|
+
if (vue) {
|
|
150
232
|
const pluginVue = await dynamicImport(import("@vitejs/plugin-vue"));
|
|
151
233
|
plugins.push(pluginVue());
|
|
152
234
|
}
|
|
235
|
+
if (react) {
|
|
236
|
+
const pluginReact = await dynamicImport(import("@vitejs/plugin-react"));
|
|
237
|
+
plugins.push(pluginReact());
|
|
238
|
+
}
|
|
153
239
|
if (isVueOrVitepress) {
|
|
154
240
|
const vueJsx = await dynamicImport(import("@vitejs/plugin-vue-jsx"));
|
|
155
241
|
plugins.push(vueJsx());
|
|
156
242
|
}
|
|
157
243
|
if (pageRoutes) {
|
|
158
244
|
const Pages = await dynamicImport(import("vite-plugin-pages"));
|
|
245
|
+
const extensions = [];
|
|
246
|
+
if (vue) {
|
|
247
|
+
extensions.push("vue");
|
|
248
|
+
}
|
|
249
|
+
if (react) {
|
|
250
|
+
extensions.push("tsx", "jsx");
|
|
251
|
+
}
|
|
159
252
|
plugins.push(Pages(
|
|
160
253
|
deepMerge(
|
|
161
254
|
{
|
|
162
255
|
dirs: "src/pages",
|
|
163
|
-
extensions
|
|
256
|
+
extensions,
|
|
164
257
|
exclude: [
|
|
165
258
|
"**/components/**",
|
|
166
259
|
"**/__tests__/**"
|
|
@@ -170,11 +263,11 @@ async function getViteConfig(Config, params) {
|
|
|
170
263
|
)
|
|
171
264
|
));
|
|
172
265
|
}
|
|
173
|
-
if (isDev && devtools) {
|
|
266
|
+
if (isDev && devtools && isVueOrVitepress) {
|
|
174
267
|
const vueDevTools = await dynamicImport(import("vite-plugin-vue-devtools"));
|
|
175
268
|
plugins.push(vueDevTools());
|
|
176
269
|
}
|
|
177
|
-
if (autoImport) {
|
|
270
|
+
if (autoImport && isVueOrVitepress) {
|
|
178
271
|
const AutoImport = await dynamicImport(import("unplugin-auto-import/vite"));
|
|
179
272
|
const ElementPlusResolverModule = await dynamicImport(import("unplugin-vue-components/resolvers"));
|
|
180
273
|
const { ElementPlusResolver } = ElementPlusResolverModule;
|
|
@@ -182,21 +275,21 @@ async function getViteConfig(Config, params) {
|
|
|
182
275
|
deepMerge(
|
|
183
276
|
{
|
|
184
277
|
imports: ["vue"],
|
|
185
|
-
resolvers:
|
|
278
|
+
resolvers: [ElementPlusResolver()],
|
|
186
279
|
dts: path.resolve(rootPath, "./typings/auto-imports.d.ts")
|
|
187
280
|
},
|
|
188
281
|
autoImport
|
|
189
282
|
)
|
|
190
283
|
));
|
|
191
284
|
}
|
|
192
|
-
if (autoComponent) {
|
|
285
|
+
if (autoComponent && isVueOrVitepress) {
|
|
193
286
|
const Components = await dynamicImport(import("unplugin-vue-components/vite"));
|
|
194
287
|
const ElementPlusResolverModule = await dynamicImport(import("unplugin-vue-components/resolvers"));
|
|
195
288
|
const { ElementPlusResolver } = ElementPlusResolverModule;
|
|
196
289
|
plugins.push(Components(
|
|
197
290
|
deepMerge(
|
|
198
291
|
{
|
|
199
|
-
resolvers:
|
|
292
|
+
resolvers: [ElementPlusResolver()],
|
|
200
293
|
globs: [],
|
|
201
294
|
dts: path.resolve(rootPath, "./typings/components.d.ts")
|
|
202
295
|
},
|
|
@@ -295,6 +388,7 @@ async function getViteConfig(Config, params) {
|
|
|
295
388
|
{
|
|
296
389
|
strategies: "generateSW",
|
|
297
390
|
registerType: "autoUpdate",
|
|
391
|
+
// 开发模式下也启用
|
|
298
392
|
devOptions: {
|
|
299
393
|
enabled: true
|
|
300
394
|
},
|
|
@@ -302,7 +396,7 @@ async function getViteConfig(Config, params) {
|
|
|
302
396
|
manifest: {
|
|
303
397
|
id: appCode ? `/${appCode}/` : "/",
|
|
304
398
|
start_url: appCode ? `/${appCode}/` : "/",
|
|
305
|
-
name: appTitle || "
|
|
399
|
+
name: appTitle || "应用",
|
|
306
400
|
short_name: appTitle || "应用",
|
|
307
401
|
description: "渐进式 Web 应用",
|
|
308
402
|
display: "standalone",
|
|
@@ -340,7 +434,7 @@ async function getViteConfig(Config, params) {
|
|
|
340
434
|
}));
|
|
341
435
|
}
|
|
342
436
|
}
|
|
343
|
-
if (autoRoutes) {
|
|
437
|
+
if (autoRoutes && isVueOrVitepress) {
|
|
344
438
|
const AutoRoutesPlugin = await dynamicImport(Promise.resolve().then(() => index));
|
|
345
439
|
plugins.push(AutoRoutesPlugin(
|
|
346
440
|
deepMerge(
|
|
@@ -389,6 +483,15 @@ async function getViteConfig(Config, params) {
|
|
|
389
483
|
if (id.includes("@vue") || id.includes("vue")) {
|
|
390
484
|
return "vue-vendor";
|
|
391
485
|
}
|
|
486
|
+
if (id.includes("antd") || id.includes("@ant-design")) {
|
|
487
|
+
return "antd-vendor";
|
|
488
|
+
}
|
|
489
|
+
if (id.includes("react-dom")) {
|
|
490
|
+
return "react-dom-vendor";
|
|
491
|
+
}
|
|
492
|
+
if (id.includes("react")) {
|
|
493
|
+
return "react-vendor";
|
|
494
|
+
}
|
|
392
495
|
return "vendor";
|
|
393
496
|
}
|
|
394
497
|
}
|
|
@@ -520,13 +623,23 @@ function createMatcher(prefixes) {
|
|
|
520
623
|
}
|
|
521
624
|
class VirtualModuleState {
|
|
522
625
|
constructor() {
|
|
626
|
+
/** 标记服务器是否正在关闭,避免关闭阶段再触发无效操作 */
|
|
523
627
|
__publicField(this, "isServerClosing", false);
|
|
628
|
+
/** 标记初始化是否完成,初始化期间的变化会被延迟处理 */
|
|
524
629
|
__publicField(this, "isInitialized", false);
|
|
630
|
+
/** 标记初始化期间是否有文件变化,初始化完成后会处理这些变化 */
|
|
525
631
|
__publicField(this, "hasPendingChange", false);
|
|
632
|
+
/** HMR 热更新的防抖函数,lodash-es debounce 返回的函数有 cancel 方法,可以手动取消 */
|
|
526
633
|
__publicField(this, "hmrDebouncedInvalidate");
|
|
634
|
+
/** watchChange 钩子的防抖函数,用于清理模块缓存 */
|
|
527
635
|
__publicField(this, "watchChangeDebouncedClear");
|
|
636
|
+
/** 文件监听器的防抖函数 */
|
|
528
637
|
__publicField(this, "watcherDebouncedInvalidate");
|
|
529
638
|
}
|
|
639
|
+
/**
|
|
640
|
+
* 清理所有防抖定时器
|
|
641
|
+
* 在服务器关闭时调用,确保不会有待执行的防抖任务
|
|
642
|
+
*/
|
|
530
643
|
clearAll() {
|
|
531
644
|
var _a, _b, _c;
|
|
532
645
|
(_a = this.hmrDebouncedInvalidate) == null ? void 0 : _a.cancel();
|
|
@@ -702,12 +815,23 @@ function createVirtualPlugin(userConfig) {
|
|
|
702
815
|
performInvalidate(server);
|
|
703
816
|
};
|
|
704
817
|
return {
|
|
818
|
+
/**
|
|
819
|
+
* 解析虚拟模块 ID
|
|
820
|
+
* 当 import 语句引用虚拟模块时,Vite 会调用此方法
|
|
821
|
+
* @param args - resolveId 的所有参数
|
|
822
|
+
* @returns 如果匹配虚拟模块 ID,返回该 ID;否则返回 undefined
|
|
823
|
+
*/
|
|
705
824
|
resolveId(...args) {
|
|
706
825
|
const [id] = args;
|
|
707
826
|
if (id === VIRTUAL_MODULE_ID || id.startsWith(`${VIRTUAL_MODULE_ID}/`))
|
|
708
827
|
return id;
|
|
709
828
|
return callUserHook(resolveId, this, ...args);
|
|
710
829
|
},
|
|
830
|
+
/**
|
|
831
|
+
* 配置解析完成钩子
|
|
832
|
+
* 在 Vite 配置解析完成后调用,用于初始化监听路径和生成类型声明文件
|
|
833
|
+
* @param args - configResolved 的所有参数
|
|
834
|
+
*/
|
|
711
835
|
configResolved(...args) {
|
|
712
836
|
const [config] = args;
|
|
713
837
|
resolvedViteConfig = config;
|
|
@@ -719,6 +843,11 @@ function createVirtualPlugin(userConfig) {
|
|
|
719
843
|
writeDtsFile(config, rootDir, dts, generateDts);
|
|
720
844
|
callUserHook(configResolved, this, ...args);
|
|
721
845
|
},
|
|
846
|
+
/**
|
|
847
|
+
* 配置开发服务器钩子
|
|
848
|
+
* 在开发服务器启动时调用,用于设置文件监听、信号处理和清理逻辑
|
|
849
|
+
* @param args - configureServer 的所有参数
|
|
850
|
+
*/
|
|
722
851
|
configureServer(...args) {
|
|
723
852
|
var _a;
|
|
724
853
|
const [server] = args;
|
|
@@ -759,6 +888,16 @@ function createVirtualPlugin(userConfig) {
|
|
|
759
888
|
});
|
|
760
889
|
callUserHook(configureServer, this, ...args);
|
|
761
890
|
},
|
|
891
|
+
/**
|
|
892
|
+
* 处理热更新钩子
|
|
893
|
+
* 当 Vite 检测到文件变化时调用,用于触发虚拟模块的失效和更新
|
|
894
|
+
* @param args - handleHotUpdate 的所有参数
|
|
895
|
+
* @returns 空数组,表示不阻止其他插件的处理
|
|
896
|
+
* @remarks
|
|
897
|
+
* - 使用防抖机制避免频繁触发
|
|
898
|
+
* - 初始化期间的变化会被延迟处理
|
|
899
|
+
* - 只处理匹配监听路径的文件变化
|
|
900
|
+
*/
|
|
762
901
|
handleHotUpdate(...args) {
|
|
763
902
|
const [ctx] = args;
|
|
764
903
|
const { server } = ctx;
|
|
@@ -786,6 +925,16 @@ function createVirtualPlugin(userConfig) {
|
|
|
786
925
|
state.hmrDebouncedInvalidate();
|
|
787
926
|
return callUserHook(handleHotUpdate, this, ...args) || [];
|
|
788
927
|
},
|
|
928
|
+
/**
|
|
929
|
+
* 监听文件变化钩子
|
|
930
|
+
* 当 Vite 的依赖预构建或文件系统检测到变化时调用
|
|
931
|
+
* 主要用于清理模块缓存,让下次加载时重新生成
|
|
932
|
+
* @param args - watchChange 的所有参数
|
|
933
|
+
* @remarks
|
|
934
|
+
* - 与 handleHotUpdate 不同,此钩子主要用于清理缓存,不触发 HMR
|
|
935
|
+
* - 使用防抖机制避免频繁清理
|
|
936
|
+
* - 初始化期间的变化会被延迟处理
|
|
937
|
+
*/
|
|
789
938
|
watchChange(...args) {
|
|
790
939
|
try {
|
|
791
940
|
const [id] = args;
|
|
@@ -817,6 +966,16 @@ function createVirtualPlugin(userConfig) {
|
|
|
817
966
|
} catch {
|
|
818
967
|
}
|
|
819
968
|
},
|
|
969
|
+
/**
|
|
970
|
+
* 加载虚拟模块内容
|
|
971
|
+
* 当 import 语句引用虚拟模块时,Vite 会调用此方法获取模块代码
|
|
972
|
+
* @param args - load 的所有参数
|
|
973
|
+
* @returns 模块代码字符串,如果 ID 不匹配则返回 undefined
|
|
974
|
+
* @remarks
|
|
975
|
+
* - 支持同步和异步的 generateModule 函数
|
|
976
|
+
* - 生成的代码会被缓存,直到模块被失效
|
|
977
|
+
* - 子路径导入(如 'virtual:routes/sub')会传入完整 ID 给 generateModule
|
|
978
|
+
*/
|
|
820
979
|
async load(...args) {
|
|
821
980
|
const [id] = args;
|
|
822
981
|
if (id === VIRTUAL_MODULE_ID || id.startsWith(`${VIRTUAL_MODULE_ID}/`)) {
|
|
@@ -826,6 +985,7 @@ function createVirtualPlugin(userConfig) {
|
|
|
826
985
|
}
|
|
827
986
|
return await callUserHook(load, this, ...args);
|
|
828
987
|
},
|
|
988
|
+
// 使用 rest 参数包含所有其他未使用的钩子(包括 name, transform, enforce 等)
|
|
829
989
|
...restHooks
|
|
830
990
|
};
|
|
831
991
|
}
|
|
@@ -972,6 +1132,7 @@ function createAutoRoutesPlugin({ routeConfig, virtualModuleId, dts, root, eager
|
|
|
972
1132
|
root,
|
|
973
1133
|
watch: watchGlobs,
|
|
974
1134
|
enforce: "pre",
|
|
1135
|
+
// 生成虚拟模块代码:仅负责产出字符串,监听/HMR/缓存由工厂统一处理
|
|
975
1136
|
generateModule: () => {
|
|
976
1137
|
const imports = [];
|
|
977
1138
|
const routes = [];
|
|
@@ -994,9 +1155,9 @@ function createAutoRoutesPlugin({ routeConfig, virtualModuleId, dts, root, eager
|
|
|
994
1155
|
${findDefaultRouteHandle}
|
|
995
1156
|
|
|
996
1157
|
const findParentRoute = ${findParentRouteHandle}
|
|
997
|
-
|
|
1158
|
+
// 用于routes
|
|
998
1159
|
const generateRoutes = ${generateRoutes};
|
|
999
|
-
|
|
1160
|
+
// 用于导出
|
|
1000
1161
|
const findDefaultRoute = ${findDefaultRouteHandle};
|
|
1001
1162
|
|
|
1002
1163
|
const routes = ${routesCode}.flat().filter(Boolean);
|
|
@@ -1005,6 +1166,7 @@ function createAutoRoutesPlugin({ routeConfig, virtualModuleId, dts, root, eager
|
|
|
1005
1166
|
export default routes;
|
|
1006
1167
|
`;
|
|
1007
1168
|
},
|
|
1169
|
+
// 生成类型声明文件
|
|
1008
1170
|
generateDts: () => `// 此文件由ViteConfig自动生成,请勿手动修改
|
|
1009
1171
|
declare module 'virtual:auto-routes' {
|
|
1010
1172
|
interface RouteModule {
|
package/es/src/_types/index.d.ts
CHANGED
|
@@ -19,35 +19,116 @@ export type QiankunPlugin = (name: string, options?: {
|
|
|
19
19
|
useDevMode?: boolean;
|
|
20
20
|
}) => PluginOption;
|
|
21
21
|
export type CDNOptions = Parameters<typeof importToCDN>[0] & {
|
|
22
|
+
/**
|
|
23
|
+
* CDN的基本url
|
|
24
|
+
*/
|
|
22
25
|
baseUrl?: string;
|
|
26
|
+
/**
|
|
27
|
+
* dev环境是否启用CDN
|
|
28
|
+
*/
|
|
23
29
|
enableInDevMode?: boolean;
|
|
24
30
|
};
|
|
25
31
|
export type VisualizerOptions = Parameters<typeof visualizer>[0];
|
|
32
|
+
/**
|
|
33
|
+
* 插件配置类型,仅在 ModeConfig 中使用
|
|
34
|
+
*/
|
|
26
35
|
export interface PluginConfig {
|
|
36
|
+
/**
|
|
37
|
+
* AutoImport配置,true表示使用默认配置,对象表示覆盖默认配置
|
|
38
|
+
*/
|
|
27
39
|
autoImport?: boolean | unpluginAutoImportOptions;
|
|
40
|
+
/**
|
|
41
|
+
* Components配置,true表示使用默认配置,对象表示覆盖默认配置
|
|
42
|
+
*/
|
|
28
43
|
autoComponent?: boolean | (unpluginVueComponentsOptions & {
|
|
44
|
+
/**
|
|
45
|
+
* 需要排除的element-plus组件
|
|
46
|
+
*/
|
|
29
47
|
elementExcludes?: string[];
|
|
48
|
+
/**
|
|
49
|
+
* 除resolve规则外,额外需要引入的组件所需匹配规则
|
|
50
|
+
*/
|
|
30
51
|
globs?: string[];
|
|
31
52
|
});
|
|
53
|
+
/**
|
|
54
|
+
* 压缩配置,true表示使用默认配置,对象表示覆盖默认配置
|
|
55
|
+
*/
|
|
32
56
|
compression?: boolean | CompressionOptions;
|
|
57
|
+
/**
|
|
58
|
+
* 图片压缩配置,true表示使用默认配置,对象表示覆盖默认配置
|
|
59
|
+
*/
|
|
33
60
|
imagemin?: boolean | ImageminOptions;
|
|
61
|
+
/**
|
|
62
|
+
* CDN配置,true表示使用默认配置,对象表示覆盖默认配置
|
|
63
|
+
*/
|
|
34
64
|
cdn?: boolean | CDNOptions;
|
|
65
|
+
/**
|
|
66
|
+
* 包预览配置,true表示使用默认配置,对象表示覆盖默认配置
|
|
67
|
+
*/
|
|
35
68
|
visualizer?: boolean | VisualizerOptions;
|
|
69
|
+
/**
|
|
70
|
+
* 自动路由配置,true表示使用默认配置,对象表示覆盖默认配置
|
|
71
|
+
*/
|
|
36
72
|
autoRoutes?: boolean | AutoRoutesConfig;
|
|
73
|
+
/**
|
|
74
|
+
* 页面路由配置(vite-plugin-pages),true表示使用默认配置,对象表示覆盖默认配置
|
|
75
|
+
*/
|
|
37
76
|
pageRoutes?: boolean | PagesOptions;
|
|
77
|
+
/**
|
|
78
|
+
* 是否启用vue-devtools
|
|
79
|
+
*/
|
|
38
80
|
devtools?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* 项目端口
|
|
83
|
+
*/
|
|
39
84
|
port?: number;
|
|
85
|
+
/**
|
|
86
|
+
* 是否在npm run dev时,自动打开浏览器
|
|
87
|
+
*/
|
|
40
88
|
open?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* dev环境是否启用qiankun
|
|
91
|
+
*/
|
|
41
92
|
qiankunDevMode?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* 是否启用qiankun
|
|
95
|
+
*/
|
|
42
96
|
qiankun?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* 命名空间,启用后在非dev环境下的envSystemCode将等于此值
|
|
99
|
+
*/
|
|
43
100
|
namespace?: string;
|
|
101
|
+
/**
|
|
102
|
+
* 是否在打包时,删除console和debugger
|
|
103
|
+
*/
|
|
44
104
|
dropConsole?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* PWA配置,true表示使用默认配置,对象表示覆盖默认配置
|
|
107
|
+
*/
|
|
45
108
|
pwa?: boolean | VitePWAOptions;
|
|
109
|
+
/**
|
|
110
|
+
* Code Inspector配置,true表示使用默认配置,对象表示覆盖默认配置
|
|
111
|
+
*/
|
|
46
112
|
codeInspector?: boolean | Parameters<typeof import('code-inspector-plugin').codeInspectorPlugin>[0];
|
|
113
|
+
/**
|
|
114
|
+
* 是否是vitepress
|
|
115
|
+
*/
|
|
47
116
|
vitepress?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* 是否是vue
|
|
119
|
+
*/
|
|
48
120
|
vue?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* 是否是react
|
|
123
|
+
*/
|
|
49
124
|
react?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* 项目标题
|
|
127
|
+
*/
|
|
50
128
|
appTitle?: string;
|
|
129
|
+
/**
|
|
130
|
+
* 项目code
|
|
131
|
+
*/
|
|
51
132
|
appCode?: string;
|
|
52
133
|
}
|
|
53
134
|
export interface ModeConfig extends PluginConfig {
|
|
@@ -65,13 +146,32 @@ export interface RouteConfig {
|
|
|
65
146
|
[prefix: string]: string | string[] | objRouteConfig;
|
|
66
147
|
}
|
|
67
148
|
export interface AutoRoutesConfig {
|
|
149
|
+
/**
|
|
150
|
+
* 路由配置
|
|
151
|
+
*/
|
|
68
152
|
routeConfig: RouteConfig;
|
|
153
|
+
/**
|
|
154
|
+
* 虚拟模块ID
|
|
155
|
+
*/
|
|
69
156
|
virtualModuleId?: string;
|
|
157
|
+
/**
|
|
158
|
+
* 声明文件路径,true表示使用默认路径,false表示不生成声明文件
|
|
159
|
+
*/
|
|
70
160
|
dts?: string | boolean;
|
|
161
|
+
/**
|
|
162
|
+
* 项目根目录路径
|
|
163
|
+
*/
|
|
71
164
|
root?: string;
|
|
72
165
|
}
|
|
73
166
|
export interface Config extends PluginConfig {
|
|
74
|
-
|
|
167
|
+
/**
|
|
168
|
+
* 根目录
|
|
169
|
+
* 如果不传入,将使用 process.cwd() 作为默认值
|
|
170
|
+
*/
|
|
171
|
+
rootPath?: string;
|
|
172
|
+
/**
|
|
173
|
+
* 环境配置
|
|
174
|
+
*/
|
|
75
175
|
mode?: {
|
|
76
176
|
base?: ModeConfig;
|
|
77
177
|
development?: ModeConfig;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 框架配置类型
|
|
3
|
+
*/
|
|
4
|
+
export interface FrameworkConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Vue 框架配置
|
|
7
|
+
*/
|
|
8
|
+
vue?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* React 框架配置
|
|
11
|
+
*/
|
|
12
|
+
react?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* VitePress 框架配置
|
|
15
|
+
*/
|
|
16
|
+
vitepress?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 框架检测结果类型
|
|
20
|
+
*/
|
|
21
|
+
export interface FrameworkResult {
|
|
22
|
+
/**
|
|
23
|
+
* Vue 框架
|
|
24
|
+
*/
|
|
25
|
+
vue: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* React 框架
|
|
28
|
+
*/
|
|
29
|
+
react: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* VitePress 框架
|
|
32
|
+
*/
|
|
33
|
+
vitepress: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 检测项目依赖中的框架
|
|
37
|
+
* 优先级:显示传入 > 检测,且优先级为 vue/react > vitepress
|
|
38
|
+
* @param config - 框架配置对象,包含 vue、react、vitepress
|
|
39
|
+
* @param rootDir - 项目根目录,如果不传入则使用 process.cwd()
|
|
40
|
+
* @returns 检测后的框架配置对象
|
|
41
|
+
*/
|
|
42
|
+
export declare function detectFramework(config: FrameworkConfig, rootDir?: string): FrameworkResult;
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import { objType } from '../../../_types/index.ts';
|
|
2
2
|
export declare function isDevFn(mode: string): boolean;
|
|
3
3
|
export declare function isProdFn(mode: string): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Whether to generate package preview
|
|
6
|
+
*/
|
|
4
7
|
export declare function isReportMode(): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* 将环境变量中的字符串值转换为对应的 JavaScript 数据类型
|
|
10
|
+
*/
|
|
5
11
|
export declare function wrapperEnv(env: Record<string, string>): objType;
|
|
12
|
+
/**
|
|
13
|
+
* Get the environment variables starting with the specified prefix
|
|
14
|
+
* @param match prefix
|
|
15
|
+
* @param confFiles ext
|
|
16
|
+
*/
|
|
6
17
|
export declare function getEnvConfig(match?: string, confFiles?: string[]): {};
|
|
18
|
+
/**
|
|
19
|
+
* Get user root directory
|
|
20
|
+
* @param dir file path
|
|
21
|
+
*/
|
|
7
22
|
export declare function getRootPath(...dir: string[]): string;
|
package/es/src/_utils/index.d.ts
CHANGED