Просмотр исходного кода

fix(frontend): H5 白屏根因修复 — exports polyfill + CSS publicPath

根因:uni-app 编译器在 tabBar 页面模块注入 exports.default.components=...
时混用自由变量 'exports'(webpack 压缩后模块参数为 a/e/t,e 才是 exports),
浏览器无全局 exports → ReferenceError 中断 pages-index-home-index chunk 执行
→ 首页白屏。custom-tab-bar 已由 main.js Vue.component 全局注册,功能不受影响。

- public/index.html(新建,uni-app H5 实际模板入口):head 内提前 polyfill
  window.exports={default:{}},消除 exports 引用错误;CSS link 用 <%= BASE_URL %>
  前缀(修复 /static/index.css 缺 /frontend/ 导致样式 404)
- index.html(项目根模板,同步 polyfill,保持一致)
- config.js 不入库(用户要求):稳健版存 /home/iwt/cfc-h5-config/config.js,
  由 cfc-deploy-251.sh 构建前注入(已单独处理)
iwt 1 неделя назад
Родитель
Сommit
4e3cf1fc37
2 измененных файлов с 47 добавлено и 0 удалено
  1. 16 0
      cfc-frontend/index.html
  2. 31 0
      cfc-frontend/public/index.html

+ 16 - 0
cfc-frontend/index.html

@@ -6,6 +6,22 @@
     <title>浠艾福</title>
     <!--preload-links-->
     <!--app-context-->
+    <!-- H5 修复:uni-app 编译器在 tabBar 页面模块注入 exports.default.components=... 时
+         使用了自由变量 'exports'(webpack 压缩后模块参数是 a/e/t,e 才是 exports),
+         浏览器没有全局 exports,导致 ReferenceError 中断组件 chunk 执行、首页白屏。
+         提前 polyfill,让注入代码挂到 window.exports 不抛错;组件注册已由 main.js 的
+         Vue.component('custom-tab-bar', CustomTabBar) 全局完成,不影响功能。 -->
+    <script>
+    if (typeof window !== 'undefined') {
+        // uni-app 编译器在 tabBar 页面模块注入 exports.default.components=... 时
+        // 混用自由变量 'exports'(webpack 压缩后模块参数为 a/e/t,e 才是 exports),
+        // 浏览器无全局 exports → ReferenceError 中断组件 chunk 执行。
+        // polyfill 需提供 window.exports 且带 .default 对象,避免再触发
+        // "Cannot read properties of undefined (reading 'components')"。
+        window.exports = window.exports || {};
+        window.exports.default = window.exports.default || {};
+    }
+    </script>
     <link rel="stylesheet" href="/static/index.css" />
 </head>
 <body>

+ 31 - 0
cfc-frontend/public/index.html

@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
+    <title>浠艾福</title>
+    <!--preload-links-->
+    <!--app-context-->
+    <!-- H5 修复:uni-app 编译器在 tabBar 页面模块注入 exports.default.components=... 时
+         使用了自由变量 'exports'(webpack 压缩后模块参数是 a/e/t,e 才是 exports),
+         浏览器没有全局 exports,导致 ReferenceError 中断组件 chunk 执行、首页白屏。
+         提前 polyfill,让注入代码挂到 window.exports 不抛错;组件注册已由 main.js 的
+         Vue.component('custom-tab-bar', CustomTabBar) 全局完成,不影响功能。 -->
+    <script>
+    if (typeof window !== 'undefined') {
+        // uni-app 编译器在 tabBar 页面模块注入 exports.default.components=... 时
+        // 混用自由变量 'exports'(webpack 压缩后模块参数为 a/e/t,e 才是 exports),
+        // 浏览器无全局 exports → ReferenceError 中断组件 chunk 执行。
+        // polyfill 需提供 window.exports 且带 .default 对象,避免再触发
+        // "Cannot read properties of undefined (reading 'components')"。
+        window.exports = window.exports || {};
+        window.exports.default = window.exports.default || {};
+    }
+    </script>
+    <link rel="stylesheet" href="<%= BASE_URL %>static/index.css" />
+</head>
+<body>
+    <div id="app"><!--app-html--></div>
+    <script type="module" src="/main.js"></script>
+</body>
+</html>