config.js 732 B

1234567891011121314151617
  1. /**
  2. * config.js —— 全站唯一「部署基址」变量。
  3. * <base href>、importmap 前缀、renderBase、路由 base 都由这里派生(规则:三处同源)。
  4. * 部署到 OBS 子目录时只改这一处(改成带结尾斜杠的前缀,如 '../hardware-lab/')。
  5. */
  6. export const APP_BASE = './';
  7. /** 从当前文档的 <base href> 得到绝对基址(末尾带 /) */
  8. export function docBase() {
  9. const b = (typeof document !== 'undefined' && document.baseURI) || '';
  10. return b.endsWith('/') ? b : b + '/';
  11. }
  12. /** 应用内路径 → 可 ESM import 的模块 URL(相对基址,绝不丢部署前缀) */
  13. export function moduleUrl(path) {
  14. return new URL(path.replace(/^\.?\//, ''), docBase()).href;
  15. }