fix: stabilize Vite 8/Rolldown beta, merge pending fixes, support Electron 42/43 - #1
Merged
Merged
Conversation
Fork release as @desirecore/electron-vite (v6.0.0-beta.2). Fixes a batch of Vite 8 / Rolldown regressions and Electron 42 support, and merges several long-pending upstream fixes. - fix(esmShim): AST-based CJS shim injection at offset 0, no longer corrupts large Vite 8/Rolldown ESM bundles (alex8088#906) - fix(swc): also set `oxc: false` to disable Vite 8 default transform (alex8088#916) - fix(config): do not throw on non-plain objects when isolating config (alex8088#902) - fix(renderer): re-root when HTML entry is outside root, avoid illegal `../` emit paths under Rolldown (alex8088#915) - fix(bytecode): compile via vm.compileFunction in the consuming process type, fixing cachedDataRejected on Electron 42 / V8 14.8 (alex8088#911, alex8088#912) - fix(bytecode): remove non-deterministic compile race (alex8088#910) - fix(bytecode): correct renderer preset plugin name; locate the compiler script relative to this module so it survives package renames - fix(modulePath): inject modulePathPlugin into the sub-build for nested `?modulePath` and re-exports (alex8088#860, alex8088#862) - fix(dev): forward signals to the Electron child and escalate to SIGKILL on restart, fixing zombie processes (alex8088#899, alex8088#734, alex8088#353) - feat: support Electron 42 targets and lazy electron install (alex8088#904) - feat(bytecode): allow RegExp for chunkAlias; protect string concat (alex8088#885) - feat(cli): add --noElectronStart (alex8088#578) and --electronPackage (alex8088#867) - feat: export workerPlugin (alex8088#480) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add Electron 43 to the node/chrome build-target tables (Node 24.17 / Chromium 150). Verified end-to-end on Electron 43 (V8 15.0), including build.bytecode compile + runtime execution. Unknown newer versions continue to fall back to the newest known target. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Stabilizes the v6 Vite 8 / Rolldown beta line by hardening several build/runtime plugins (esm shim, bytecode, modulePath, swc), improving Electron dev-process lifecycle handling, and expanding Electron version support (42/43) while publishing this fork as @desirecore/electron-vite.
Changes:
- Fixes multiple Vite 8 / Rolldown regressions (AST-driven esm shim injection, renderer root re-rooting for out-of-root HTML inputs, nested
?modulePathsupport, SWC disabling Oxc). - Reworks bytecode compilation/loader to be Electron 42+ (V8 14.8+) compatible and deterministic; adds
chunkAliasRegExp support and string-concat protection. - Improves CLI/dev ergonomics (signal forwarding, restart kill escalation,
--noElectronStart,--electronPackage) and updates fork packaging/docs.
Reviewed changes
Copilot reviewed 14 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils.ts | Adjusts deepClone behavior for non-plain objects to avoid throwing during config isolation. |
| src/server.ts | Adds --noElectronStart support and introduces SIGKILL fallback on hot-reload restarts. |
| src/plugins/worker.ts | Exposes workerPlugin as a named export while preserving default export. |
| src/plugins/swc.ts | Disables both esbuild and Vite 8’s default oxc transformer when using SWC. |
| src/plugins/modulePath.ts | Re-injects modulePathPlugin into sub-builds to support nested ?modulePath. |
| src/plugins/esmShim.ts | Switches esm shim injection to AST-based detection and prepends at offset 0. |
| src/plugins/electron.ts | Re-roots renderer build when HTML inputs live outside root to satisfy Rolldown emit rules. |
| src/plugins/bytecode.ts | Refactors bytecode compilation/loader for Electron 42+ compatibility and determinism; extends options. |
| src/index.ts | Re-exports worker plugin from package entry. |
| src/electron.ts | Adds Electron 42/43 targets, lazy binary install for Electron 42+, signal forwarding, and custom pkg support. |
| src/cli.ts | Adds --noElectronStart and --electronPackage, wiring them into env/config. |
| README.md | Updates install instructions for fork package name while keeping CLI name. |
| package.json | Renames package to @desirecore/electron-vite, bumps version, updates repo metadata/publishConfig. |
| CHANGELOG.md | Documents beta.2/beta.3 changes and Linux/Xvfb note for bytecode. |
| bin/electron-bytecode.cjs | Reworks bytecode compiler to run in appropriate Electron process type (main vs renderer). |
| bin/electron-bytecode-preload.cjs | Adds renderer preload compiler for preload-chunk bytecode generation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
213
to
+217
| const isBytecodeChunk = (chunkName: string): boolean => { | ||
| return transformAllChunks || _chunkAlias.some(alias => alias === chunkName) | ||
| return ( | ||
| transformAllChunks || | ||
| _chunkAlias.some(alias => (alias instanceof RegExp ? alias.test(chunkName) : alias === chunkName)) | ||
| ) |
Comment on lines
+47
to
54
| function hasCJSIdentifier(root: AstNode): boolean { | ||
| const queue: AstNode[] = [root] | ||
| while (queue.length > 0) { | ||
| const node = queue.pop() | ||
| if (!node || typeof node !== 'object' || !node.type) continue | ||
|
|
||
| if (node.type === 'Identifier' && typeof node.name === 'string' && CJSIdentifiers.has(node.name)) return true | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
将
v6.0.0-beta.1(Vite 8 / Rolldown 迁移已完成但停滞)稳定为可发布状态,修复全部 Vite 8 / Rolldown 回归、新增 Electron 42/43 支持,并合并一批长期未处理的上游有价值 PR。本 fork 发布为@desirecore/electron-vite(CLI 命令仍为electron-vite)。所有改动均在 macOS / Node 25 / Vite 8.1 / Electron 41.9 · 42.5 · 43.0-beta 上做了真实端到端验证(构建 + 启动真实 Electron 应用自检),而非仅单元/逻辑验证。
修复的 Vite 8 / Rolldown 回归
renderChunk旧实现用正则在整段已渲染 chunk 上找“最后一个 import”,大包(如 3.5MB)里字符串字面量内嵌的import ... from '...'文本被误判,CJS shim 被注入到字符串内部导致 chunk 损坏、Rolldown 输出空入口。改为 AST 驱动(this.parse仅遍历顶层节点判断真实 CJS 引用)+ offset 0prepend注入(ESM import 会提升,置顶恒合法),彻底消除错位故障面。Vite 8 默认转换器由 esbuild 切换为 Oxc,
swcPlugin仅设esbuild: false不再生效并告警。改为同时返回{ esbuild: false, oxc: false }(旧版 Vite 忽略oxc字段,向后兼容)。deepClone遇到类实例(如@rolldown/plugin-babel+reactCompilerPreset())直接throw。改为对非 plain object 按引用透传(与 Function/RegExp 分支一致)。../emit 路径 (electron-vite preview 打包报错:vite:build-html 传入带 ../ 的非法 fileName alex8088/electron-vite#915)Vite 不对用户显式
rollupOptions.input做 root 相对解析,导致vite:build-html拼出../../...,被 Rolldown 1.x 的 emitFile 校验硬拒。当 HTML 入口落在 root 外时,将 renderer root 重定位为入口公共祖先目录。clean 模式剥离了子构建的内置插件(含
modulePathPlugin自身),导致嵌套?modulePath被内联、且出现 “default is not exported”。修复后嵌套?modulePath正确独立成块、导出可用。bytecode(核心修复 + 增强)
cachedDataRejected崩溃 (build.bytecode crashes with "cachedDataRejected" on Electron 42 (Chromium 148 / V8 14.8) alex8088/electron-vite#911, fix(bytecodePlugin): support Electron 42 / V8 14.8 code cache alex8088/electron-vite#912)V8 14.8 起 code cache 绑定 per-process-type snapshot/isolate checksum + flag hash,且
vm.Script占位源不再运行 cache。改为用vm.compileFunction在将消费该 chunk 的进程类型内编译(main chunk → 主进程;preload chunk →sandbox:false渲染进程 preload,新增bin/electron-bytecode-preload.cjs),loader 同样改用vm.compileFunction+ 每文件唯一占位(规避 V8 in-isolate CompilationCache 命中错误 SFI),删除脆弱的 flag-hash 头补丁。该方案无硬编码 V8 头偏移,天然向前兼容更新 V8。旧
compileToBytecode的stdout 'end'与exit双 resolve 存在竞态,可能 resolve 空/截断 buffer 产出坏包。改为临时文件 IO + exit 后读取 + 空/缺输出 reject。vite:electron-renderer-preset-config→vite:electron-renderer-config-preset),原笔误使useInRenderer恒为 false。chunkAlias支持RegExp(及 string/RegExp 混合数组)(feat(bytecode): support RegExp for chunkAlias option alex8088/electron-vite#885)Math.random()XOR 混淆,因其破坏构建确定性)xvfb-run的可操作报错;临时文件try/finally清理;编译失败 reject 为构建失败而非产出空.jsc。Electron 运行时与 CLI
父进程注册
SIGINT/SIGTERM/SIGHUP转发给子进程;热重载重启时先 SIGTERM、超时再 SIGKILL。electron/install.js(Support Electron 42 alex8088/electron-vite#904)(Electron 42 取消了 postinstall 下载)。--noElectronStart(dev 只起 server 不启 electron)(feat: addnoElectronStartCLI option to thedevcommand alex8088/electron-vite#578)--electronPackage <name>(自定义 Electron 包名)(feat: support custom Electron package name alex8088/electron-vite#867)workerPlugin(feat: export worker plugin alex8088/electron-vite#480)验证证据(均真实复现/运行)
reactCompilerPreset()+@rolldown/plugin-babel原文配置构建通过../?modulePath独立成块、运行时路径正确、无 default 报错add=5)、无cachedDataRejected.jsc哈希完全一致未覆盖(已在 CHANGELOG/文档标注)
Windows / Linux 未在本机验证;Linux 下
build.bytecode需xvfb-run。包
@desirecore/electron-vite@6.0.0-beta.2与@6.0.0-beta.3(含 Electron 43 target),latest与beta均指向6.0.0-beta.3。bin命令保留electron-vite以兼容现有脚本。🤖 Generated with Claude Code