Skip to content

Commit 6e6ea62

Browse files
committed
feat: 兼容src是相对路径的形式
1 parent 53cbdd8 commit 6e6ea62

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/utils/url-util.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ function formatScriptSrcToUrl(scriptSrc) {
2323
// 比如可能会是一个TrustedScriptURL
2424
scriptSrc = scriptSrc + "";
2525

26+
// 正常格式直接返回
27+
if (scriptSrc.startsWith("http://") || scriptSrc.startsWith("https://")) {
28+
return scriptSrc;
29+
}
30+
2631
// 兼容CDN URL
2732
// 示例:"//statics.moonshot.cn/kimi-chat/shared-K0TvIN461soURJCs7nh6uxcQiCM_.04bc3959.async.js"
2833
if (scriptSrc.startsWith("//")) {
@@ -40,7 +45,9 @@ function formatScriptSrcToUrl(scriptSrc) {
4045
return window.location.origin + scriptSrc;
4146
}
4247

43-
return scriptSrc;
48+
// 相对路径
49+
// "static/js/chunk-19a101ae.45e69b5c.js"
50+
return window.location.origin + "/" + scriptSrc;
4451
}
4552

4653
module.exports = {

webpack.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = env => {
77
return merge(common, {
88
mode: "none",
99
//开启这个可以在开发环境中调试代码
10-
devtool: "source-map",
10+
// devtool: "source-map",
1111
devServer: {
1212
static: false,
1313
allowedHosts: "all",

0 commit comments

Comments
 (0)