hifun-tools 1.3.24 → 1.3.26
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/dist/init/getResource.js
CHANGED
|
@@ -1,38 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 通用资源加载函数(支持 Vite
|
|
2
|
+
* 通用资源加载函数(支持 Vite 与 Webpack)
|
|
3
3
|
* @param path - 相对路径,如 "tenant/config.json" 或 "tenant/logo.png"
|
|
4
4
|
*/
|
|
5
5
|
export function getResource(path) {
|
|
6
6
|
const isVite = typeof import.meta !== "undefined" && !!import.meta.env;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const isWebpack = !isRspack && // 不冲突:优先识别 Rspack
|
|
13
|
-
(typeof __webpack_require__ === "function" ||
|
|
14
|
-
(typeof require !== "undefined" &&
|
|
15
|
-
typeof require.context === "function"));
|
|
16
|
-
// ---------------- RSPACK ----------------
|
|
17
|
-
if (isRspack) {
|
|
18
|
-
try {
|
|
19
|
-
const ctx = require.context("/config", true, /\.(json|png|jpg|jpeg|svg|webp)$/);
|
|
20
|
-
const files = ctx.keys();
|
|
21
|
-
const match = files.find((key) => key.endsWith(path));
|
|
22
|
-
if (!match) {
|
|
23
|
-
console.warn(`[getResource] 未找到文件: ${path}`);
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
return ctx(match);
|
|
27
|
-
}
|
|
28
|
-
catch (e) {
|
|
29
|
-
console.error("[getResource] Rspack context 加载失败", e);
|
|
30
|
-
}
|
|
7
|
+
const isWebpack = typeof __webpack_require__ === "function" ||
|
|
8
|
+
(typeof require !== "undefined" &&
|
|
9
|
+
typeof require.context === "function");
|
|
10
|
+
if (process.env.__rspack__) {
|
|
11
|
+
return;
|
|
31
12
|
}
|
|
32
|
-
// ---------------- VITE ----------------
|
|
33
13
|
else if (isVite) {
|
|
34
|
-
|
|
35
|
-
const modules = glob([
|
|
14
|
+
// ---------------- VITE ----------------
|
|
15
|
+
const modules = import.meta.glob([
|
|
36
16
|
"/config/**/*.json",
|
|
37
17
|
"/config/**/*.png",
|
|
38
18
|
"/config/**/*.jpg",
|
|
@@ -48,10 +28,11 @@ export function getResource(path) {
|
|
|
48
28
|
console.warn(`[getResource] 未找到文件: ${path}`);
|
|
49
29
|
return null;
|
|
50
30
|
}
|
|
51
|
-
|
|
31
|
+
const [, mod] = match;
|
|
32
|
+
return mod;
|
|
52
33
|
}
|
|
53
|
-
// ---------------- WEBPACK ----------------
|
|
54
34
|
else if (isWebpack) {
|
|
35
|
+
// ---------------- WEBPACK ----------------
|
|
55
36
|
const ctx = require.context("/config", true, /\.(json|png|jpg|jpeg|svg|webp)$/);
|
|
56
37
|
const files = ctx.keys();
|
|
57
38
|
const match = files.find((key) => key.endsWith(path));
|
|
@@ -61,6 +42,6 @@ export function getResource(path) {
|
|
|
61
42
|
}
|
|
62
43
|
return ctx(match);
|
|
63
44
|
}
|
|
64
|
-
console.error("[getResource] 不支持的构建环境(需要 Vite
|
|
45
|
+
console.error("[getResource] 不支持的构建环境(需要 Vite 或 Webpack)");
|
|
65
46
|
return null;
|
|
66
47
|
}
|
package/dist/init/index.js
CHANGED
|
@@ -97,7 +97,7 @@ class InitCls {
|
|
|
97
97
|
this.tenant = tenantInfo.tenant;
|
|
98
98
|
this.tenantConfig = getResource(`${tenantInfo.tenant}/config.json`);
|
|
99
99
|
this.initialized = true;
|
|
100
|
-
console.info(`🏢 严格加载租户成功: ${this.tenant}
|
|
100
|
+
console.info(`🏢 严格加载租户成功: ${this.tenant}`);
|
|
101
101
|
return this.tenant;
|
|
102
102
|
}
|
|
103
103
|
catch (error) {
|
|
@@ -134,9 +134,9 @@ class InitCls {
|
|
|
134
134
|
const response = await fetch(`/lineAddress.txt?t=${Date.now()}`);
|
|
135
135
|
const configText = await response.text();
|
|
136
136
|
let baseUrl = JSON.parse(AesDecrypt(configText));
|
|
137
|
-
const { lineGroup
|
|
137
|
+
const { lineGroup } = this.getTenantDict();
|
|
138
138
|
const dictList = this.getTenantDictList();
|
|
139
|
-
baseUrl = filterSmartLines(dictList, baseUrl, lineGroup
|
|
139
|
+
baseUrl = filterSmartLines(dictList, baseUrl, lineGroup);
|
|
140
140
|
if (Array.isArray(baseUrl)) {
|
|
141
141
|
try {
|
|
142
142
|
this.domainBaseUrl = toStandardUrl(await getOptimalDecodedString(baseUrl));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function viteLoadSync(path: string): any;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// viteResource.ts
|
|
2
|
+
export function viteLoadSync(path) {
|
|
3
|
+
const modules = import.meta.glob([
|
|
4
|
+
"/config/**/*.json",
|
|
5
|
+
"/config/**/*.png",
|
|
6
|
+
"/config/**/*.jpg",
|
|
7
|
+
"/config/**/*.jpeg",
|
|
8
|
+
"/config/**/*.svg",
|
|
9
|
+
"/config/**/*.webp",
|
|
10
|
+
], { eager: true, import: "default" });
|
|
11
|
+
const match = Object.entries(modules).find(([key]) => key.endsWith(path));
|
|
12
|
+
return match ? match[1] : null;
|
|
13
|
+
}
|