@hzab/data-model 1.7.5 → 1.8.0
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/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/src/public-utils.js +17 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取 public 文件路径(自动拼接 hash 数据)
|
|
3
|
+
* @param {*} url 文件路径
|
|
4
|
+
* @param {*} opt
|
|
5
|
+
*/
|
|
6
|
+
export function getPublicUrl(url, opt = {}) {
|
|
7
|
+
if (typeof url !== "string") {
|
|
8
|
+
return url;
|
|
9
|
+
}
|
|
10
|
+
const { isFullPath } = opt || {};
|
|
11
|
+
let baseURL = (process.env.WEBPACK_PUBLIC_PATH || ".")?.replace(/^\//, "")?.replace(/\/$/, "");
|
|
12
|
+
if (isFullPath) {
|
|
13
|
+
const fullPathname = (location.origin + location.pathname).replace(/[^\/]+.html\/?$/, "").replace(/\/$/, "");
|
|
14
|
+
return `${fullPathname}/${baseURL?.replace(/^\./, "")}/${url?.replace(/^\//, "")}`;
|
|
15
|
+
}
|
|
16
|
+
return `${baseURL}/${url?.replace(/^\//, "")}`;
|
|
17
|
+
}
|