hifun-tools 1.3.24 → 1.3.25
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.d.ts +1 -1
- package/dist/init/getResource.js +12 -34
- package/dist/init/index.js +2 -2
- package/package.json +1 -1
package/dist/init/getResource.js
CHANGED
|
@@ -1,38 +1,15 @@
|
|
|
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
|
-
|
|
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
|
-
}
|
|
31
|
-
}
|
|
32
|
-
// ---------------- VITE ----------------
|
|
33
|
-
else if (isVite) {
|
|
34
|
-
const { glob } = import.meta;
|
|
35
|
-
const modules = glob([
|
|
7
|
+
const isWebpack = typeof __webpack_require__ === "function" ||
|
|
8
|
+
(typeof require !== "undefined" &&
|
|
9
|
+
typeof require.context === "function");
|
|
10
|
+
if (isVite) {
|
|
11
|
+
// ---------------- VITE ----------------
|
|
12
|
+
const modules = import.meta.glob([
|
|
36
13
|
"/config/**/*.json",
|
|
37
14
|
"/config/**/*.png",
|
|
38
15
|
"/config/**/*.jpg",
|
|
@@ -48,10 +25,11 @@ export function getResource(path) {
|
|
|
48
25
|
console.warn(`[getResource] 未找到文件: ${path}`);
|
|
49
26
|
return null;
|
|
50
27
|
}
|
|
51
|
-
|
|
28
|
+
const [, mod] = match;
|
|
29
|
+
return mod;
|
|
52
30
|
}
|
|
53
|
-
|
|
54
|
-
|
|
31
|
+
if (isWebpack) {
|
|
32
|
+
// ---------------- WEBPACK ----------------
|
|
55
33
|
const ctx = require.context("/config", true, /\.(json|png|jpg|jpeg|svg|webp)$/);
|
|
56
34
|
const files = ctx.keys();
|
|
57
35
|
const match = files.find((key) => key.endsWith(path));
|
|
@@ -61,6 +39,6 @@ export function getResource(path) {
|
|
|
61
39
|
}
|
|
62
40
|
return ctx(match);
|
|
63
41
|
}
|
|
64
|
-
console.error("[getResource] 不支持的构建环境(需要 Vite
|
|
42
|
+
console.error("[getResource] 不支持的构建环境(需要 Vite 或 Webpack)");
|
|
65
43
|
return null;
|
|
66
44
|
}
|
package/dist/init/index.js
CHANGED
|
@@ -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));
|