Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/index-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
ENABLE_MULTI_TENANT_MODE = ''
BK_IAM_SAAS_HOST = ''
BK_PERSONAL_CENTER_URL = ''
BK_STATIC_URL = ''
BK_SITE_PATH = ''

return {
SITE_URL: SITE_URL,
Expand Down Expand Up @@ -93,6 +95,8 @@
ENABLE_MULTI_TENANT_MODE,
BK_IAM_SAAS_HOST,
BK_PERSONAL_CENTER_URL,
BK_STATIC_URL,
BK_SITE_PATH,
}
})()
window.$DHCP = window.PROJECT_CONFIG.BKAPP_ENABLE_DHCP === 'True'
Expand Down
63 changes: 63 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
const ENABLE_MULTI_TENANT_MODE = '{{ ENABLE_MULTI_TENANT_MODE }}'
const BK_IAM_SAAS_HOST = '{{ BK_IAM_SAAS_HOST }}'
const BK_PERSONAL_CENTER_URL = '{{ BK_PERSONAL_CENTER_URL }}'
const BK_SITE_PATH = '{{ BK_SITE_PATH }}'
const BK_STATIC_URL = '{{ BK_STATIC_URL }}'


return {
APP_CODE,
Expand Down Expand Up @@ -97,13 +100,73 @@
ENABLE_MULTI_TENANT_MODE,
BK_IAM_SAAS_HOST,
BK_PERSONAL_CENTER_URL,
BK_STATIC_URL,
BK_SITE_PATH,
}
})()
window.$DHCP = window.PROJECT_CONFIG.BKAPP_ENABLE_DHCP === 'True'
</script>
</head>
<body>
<div id="app"></div>
<script>
window.BK_SITE_PATH = "{{ BK_SITE_PATH }}";
window.BK_STATIC_URL = "{{ BK_STATIC_URL }}";

window.__loadAssetsUrl__ = function(src){
function joinPath(...paths) {
// 过滤 null/undefined
const validPaths = paths.filter(p => p != null).map(String);

if (validPaths.length === 0) return '';

// 检查是否以根路径开头
const startsWithRoot = validPaths[0].startsWith('/');

// 标准化每个路径片段:移除首尾多余斜杠
const normalized = validPaths.map((p, i) => {
if (i === 0) {
// 第一个路径:只移除尾部斜杠(保留开头的 /)
return p.replace(/[\/]+$/, '');
} else {
// 其他路径:移除首尾斜杠
return p.replace(/^[\/]+|[\/]+$/g, '');
}
}).filter(p => p !== '');

// 拼接
let result = normalized.join('/');

// 如果原始第一个路径是根路径,确保结果以 / 开头
if (startsWithRoot && result !== '') {
result = '/' + result.replace(/^\/+/, '');
}

return result || (startsWithRoot ? '/' : '');
}
return joinPath(window.BK_STATIC_URL, src);
}
function loadScript (src) {
const script = document.createElement('script');
script.src = window.__loadAssetsUrl__(src);
document.body.appendChild(script);
}
function loadStyle (href) {
const link = document.createElement('link');
link.type = "text/css";
link.rel = "stylesheet";
link.href = window.__loadAssetsUrl__(href);
document.head.appendChild(link);
}
</script>
<script>
<% for (var chunk of htmlWebpackPlugin.files.js) { %>
loadScript("<%= chunk %>");
<% } %>
<% for (var chunk of htmlWebpackPlugin.files.css) { %>
loadStyle("<%= chunk %>");
<% } %>
</script>
<script src="{{ STATIC_URL }}nodeman/lib.bundle.js?t=<%= htmlWebpackPlugin.options.bundlehash %>"></script>
</body>
</html>
10 changes: 10 additions & 0 deletions frontend/src/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html lang="en">
<head>
<title>{{ WEB_TITLE }}</title>
</head>
<body>
<div id="app"></div>
<script src="/src/main.ts" type="module"></script>
</body>
</html>
1 change: 1 addition & 0 deletions frontend/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '../static/webpack_public_path';
import './public-path';
import Vue from 'vue';

Expand Down
2 changes: 2 additions & 0 deletions frontend/static/webpack_public_path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// webpack_public_path.js
__webpack_public_path__ = window.BK_STATIC_URL;
3 changes: 2 additions & 1 deletion frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"include": [
"src/**/*",
".eslintrc.js",
"local_settings.js"
"local_settings.js",
"static/webpack_public_path.js"
],
"exclude": [
"node_modules"
Expand Down
Loading