feat: add electron-forge bundle CLI command#4164
feat: add electron-forge bundle CLI command#4164bglgwyng wants to merge 2 commits intoelectron:mainfrom
electron-forge bundle CLI command#4164Conversation
Add a standalone `bundle` command that runs only the bundling step (generateAssets + prePackage hooks) without invoking @electron/packager. This ensures the same webpack/vite config is used as `package` while allowing users to produce bundle output independently. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
I don't think this API surface makes sense, it feels like an arbitrary list of hooks are called in a sequence that doesn't match reality in a production build. If you want to e2e test something you should be e2e testing the actual asset, not an asset spoof-built to be close to that asset. I'm a |
|
I appreciate the criticism, and I agree that the current implementation has issues — that's why I left the open questions in the PR description. That said, the underlying need still stands: there's no stable way to run the same webpack/vite build that Forge runs internally without going through the full Beyond e2e testing, there's a practical gap in Forge's current workflow. Forge already goes beyond pure build tooling — it provides I'm aware the current design of this PR doesn't cleanly solve this — that's exactly why I outlined the alternative approaches in the open questions. Before I invest more time into the implementation details, I'd like to align on whether this is a problem worth solving within Forge. Do you agree there's a gap here, even if this particular API shape isn't the right answer? |
Motivation
Currently, running a production bundling step (webpack/vite) requires running
electron-forge package, which also invokes@electron/packagerto download Electron binaries, copy source files, and produce a native app bundle. This is slow and unnecessary when you only need the bundled output — for example:electron .to test against realistic builds, without the overhead of full packaging.Summary
Add a standalone
bundlecommand that runs only the bundling step (generateAssets+prePackagehooks) without invoking@electron/packager.Open questions
1. Should the command include a post-bundling cleanup step?
The webpack plugin's
prePackagehook moves build output from.webpack/into.webpack/{arch}/(e.g..webpack/x64/main/). This is designed so@electron/packagercan copy all arch builds at once and later extract the correct one per target viapackageAfterCopy.Without the packager, the output stays at
.webpack/{arch}/main/, which doesn't matchpackage.json'smain: ".webpack/main"— soelectron .won't work directly afterbundle.Options:
bundleonly runs the hooks, users handle the output structure themselvespostBundlehook so plugins can clean up their own output (e.g. flatten.webpack/{arch}/→.webpack/), keeping plugin internals encapsulatedbundleinvokepackageAfterCopy— but this hook is designed for a different context (packager's copied build path, not the source project)2. Does the
{arch}subfolder strategy make sense forbundle?The
{arch}/subfolder pattern in the webpack plugin was designed for multi-arch packaging where all arches coexist before the packager copies them out. Forbundle(especially for e2e testing on the current machine), this intermediate structure adds complexity. However, changingprePackagebehavior based on the calling context would require plumbing new information through the hook system.3. Should
--archand--platformbe kept?These flags are passed through to
prePackageand behave identically topackage. For the primary use case (e2e testing), only the host arch is needed. Removing them would simplify the command but break consistency with other commands (package,make).Test plan
electron-forge bundlerunsgenerateAssets+prePackagehooks with webpack pluginelectron-forge bundlerunsgenerateAssets+prePackagehooks with vite plugin--archand--platformflags are passed through correctly🤖 Generated with Claude Code