兼容机房的 Chrome 94:打包目标改成 Chrome / Edge 94;polyfills.ts 补 crypto.randomUUID(http 打开时没有)、structuredClone(只复制普通数据)、findLast / findLastIndex;vite.config.ts 加小插件,把代码块之间的 import("./X.js") 改成 /assets/ 开头的绝对路径(Chrome 94 有时相对网页地址解析,拿到首页 HTML 一片空白),改过的代码块换新文件名;容器查询改成 ResizeObserver 量宽度加 class(实训台三档布局、设计器窄时隐藏提示);:has() 改成 class(只读、禁用文本框灰底,没标题的分组框)。旧浏览器提示改成 94 以上,设计方案记录实测
CI/CD / test (push) Canceled after 0s
CI/CD / deploy (push) Canceled after 0s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
xuyueandClaude Opus 5.5 committed 2026-10-28 12:58:25 +08:00
1 parent ab933d1896
commit 6a18bdf2e4
8 files changed
+130 -41

No files matched your search

+33 -2
View File
@@ -1,8 +1,39 @@
import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'
import { defineConfig, type Plugin } from 'vite'
/**
* 打包后的代码块之间按需加载写的是 import("./X.js"),应该相对于代码块自己(/assets/)解析。
* Chrome 94 在 Promise 回调里调用 import() 时(Vite 的预加载就是这样)有时会相对于网页地址解析,
* 去请求 /X.js、拿到首页 HTML,页面一片空白,时好时坏。改成 /assets/X.js 这样的绝对路径就不受影响。
*/
function absoluteDynamicImports(): Plugin {
let prefix = '/assets/'
return {
name: 'absolute-dynamic-imports',
apply: 'build',
configResolved(config) {
prefix = `${config.base}${config.build.assetsDir}/`
},
// 文件名的 hash 在 generateBundle 之前就算好了,这里让改过的代码块换个文件名,浏览器不会用缓存里没改过的旧文件
augmentChunkHash(chunk) {
if (chunk.dynamicImports.length > 0) return 'absolute-dynamic-imports'
},
// 等 Vite 按 import("./X.js") 找出每个代码块要预加载的 CSS 和依赖之后再改
generateBundle: {
order: 'post',
handler(_, bundle) {
for (const chunk of Object.values(bundle)) {
if (chunk.type === 'chunk') chunk.code = chunk.code.replace(/\bimport\((["'])\.\//g, `import($1${prefix}`)
}
},
},
}
}
export default defineConfig({
plugins: [vue()],
plugins: [vue(), absoluteDynamicImports()],
// 机房电脑的浏览器是 Chrome 94:语法和 CSS 按它转换,缺的功能在 src/polyfills.ts 里补
build: { target: ['chrome94', 'edge94'] },
server: {
port: 5173,
proxy: {