Skip to main content

介绍 Electron Forge 6

· 11 min read

我们很高兴地宣布,Electron Forge v6.0.0 现已发布!此次发布是 Forge 自 2018 年以来的首次重大版本更新,并将项目从 electron-userland 转移到 Github 上的主要 electron 组织中。

🌐 We are excited to announce that Electron Forge v6.0.0 is now available! This release marks the first major release of Forge since 2018 and moves the project from electron-userland into the main electron organization on Github.

继续阅读,了解最新动态以及你的应用如何应用 Electron Forge!

🌐 Keep on reading to see what's new and how your app can adopt Electron Forge!

什么是 Electron Forge?

🌐 What is Electron Forge?

Electron Forge 是一个用于打包和分发 Electron 应用的工具。它将 Electron 的构建工具生态系统统一到一个可扩展的界面中,使任何人都可以直接开始制作 Electron 应用。

亮点功能包括:

🌐 Highlight features include:

  • 📦 应用打包与代码签名
  • 🚚 可在 Windows、macOS 和 Linux 上自定义安装程序(DMG、deb、MSI、PKG、AppX 等)
  • ☁️ 面向云提供商(GitHub、S3、Bitbucket 等)的自动发布进程
  • ⚡️ 易于使用的 webpack 和 TypeScript 模板
  • ⚙️ 原生 Node.js 模块支持
  • 🔌 可扩展的 JavaScript 插件 API
进一步阅读

访问 Why Electron Forge 解释文档,了解更多关于 Forge 的理念和架构。

🌐 Visit the Why Electron Forge explainer document to learn more about Forge's philosophy and architecture.

v6 有什么新功能?

🌐 What's new in v6?

完全重写

🌐 Completely rewritten

从 v1 到 v5,Electron Forge 基于现已停止维护的 electron-compile 项目。Forge 6 是对该项目的全面重写,采用了新的模块化架构,可以扩展以满足任何 Electron 应用的需求。

🌐 From v1 to v5, Electron Forge was based on the now-discontinued electron-compile project. Forge 6 is a complete rewrite of the project with a new modular architecture that can be extended to meet any Electron application's needs.

在过去几年里,Forge v6.0.0-beta 已经实现了与 v5 的功能等同,并且代码更迭明显减缓,使该工具准备好被广泛采用。

🌐 In the past few years, Forge v6.0.0-beta has achieved feature parity with v5 and code churn has slowed down dramatically, making the tool ready for general adoption.

不要安装错误的软件包

对于 5 及以下版本,Electron Forge 发布在 npm 的 electron-forge 包上。从 v6 重写开始,Forge 改为以单仓库项目的形式组织,包含许多较小的子项目。

🌐 For versions 5 and below, Electron Forge was published to the electron-forge package on npm. Starting with the v6 rewrite, Forge is instead structured as a monorepo project with many smaller projects.

官方支持

🌐 Officially supported

从历史上看,Electron 的维护者对构建工具持无偏见态度,将这项任务交给各种社区包。然而,随着 Electron 项目的成熟,新入门的 Electron 开发者越来越难以理解他们需要哪些工具来构建和分发应用。

🌐 Historically, Electron maintainers have been unopinionated about build tooling, leaving the task to various community packages. However, with Electron maturing as a project, it has become harder for new Electron developers to understand which tools they need to build and distribute their apps.

为了帮助指导 Electron 开发者进行分发进程,我们决定将 Forge 定为 Electron 的官方全功能构建管道

🌐 To help guide Electron developers in the distribution process, we have have decided to make Forge the official batteries-included build pipeline for Electron.

在过去的一年里,我们一直在将 Forge 慢慢整合到官方的 Electron 文档中,最近我们已将 Forge 从它旧的存放位置 electron-userland/electron-forge 移动到了 electron/forge 仓库。现在,我们终于准备好向大众发布 Electron Forge 了!

🌐 Over the past year, we have been slowly integrating Forge into the official Electron documentation, and we have recently moved Forge over from its old home in electron-userland/electron-forge to the electron/forge repo. Now, we are finally ready to release Electron Forge to a general audience!

入门

🌐 Getting started

初始化新的 Forge 项目

🌐 Initializing a new Forge project

可以使用 create-electron-app CLI 脚本来搭建一个新的 Electron Forge 项目。

🌐 Scaffolding a new Electron Forge project can be done using the create-electron-app CLI script.

yarn create electron-app my-app --template=webpack
cd my-app
yarn start

该脚本将在 my-app 文件夹中创建一个 Electron 项目,采用完全的 JavaScript 打包并预配置构建流水线。

🌐 The script will create an Electron project in the my-app folder with completely JavaScript bundling and a preconfigured build pipeline.

欲了解更多信息,请参阅 Forge 文档中的《入门指南》。

🌐 For more info, see the Getting Started guide in the Forge docs.

一流的 Webpack 支持

上面的代码片段使用了 Forge 的 [Webpack 模板],我们推荐将其作为新 Electron 项目的起点。该模板基于 @electron-forge/plugin-webpack 插件构建,该插件以几种方式将 webpack 与 Electron Forge 集成,包括:

🌐 The above snippet uses Forge's Webpack Template, which we recommend as a starting point for new Electron projects. This template is built around the @electron-forge/plugin-webpack plugin, which integrates webpack with Electron Forge in a few ways, including:

  • 通过 webpack-dev-server 提升本地开发进程,包括对渲染器中 HMR 的支持;
  • 在应用打包之前处理 webpack 包的构建逻辑;以及
  • 在 Webpack 打包进程中添加对原生 Node 模块的支持。

如果你需要 TypeScript 支持,可以考虑使用 [Webpack + TypeScript 模板]。

🌐 If you need TypeScript support, consider using the Webpack + TypeScript Template instead.

导入现有项目

🌐 Importing an existing project

Electron Forge CLI 还包含用于导入现有 Electron 项目的命令。

🌐 The Electron Forge CLI also contains an import command for existing Electron projects.

cd my-app
yarn add --dev @electron-forge/cli
yarn electron-forge import

当你使用 import 命令时,Electron Forge 会添加一些核心依赖并创建一个新的 forge.config.js 配置。如果你已经有任何现有的构建工具(例如 Electron Packager、Electron Builder 或 Forge 5),它将尝试迁移尽可能多的设置。你的一些现有配置可能需要手动迁移。

🌐 When you use the import command, Electron Forge will add a few core dependencies and create a new forge.config.js configuration. If you have any existing build tooling (e.g. Electron Packager, Electron Builder, or Forge 5), it will try to migrate as many settings as possible. Some of your existing configuration may need to be migrated manually.

手动迁移的详细信息可以在 Forge 的 [导入文档] 中找到。如果你需要帮助,请访问 我们的 Discord 服务器

🌐 Manual migration details can be found in the Forge import documentation. If you need help, please stop by our Discord server!

为什么要切换到 Forge?

🌐 Why switch to Forge?

如果你已经拥有用于打包和发布 Electron 应用的工具,那么采用 Electron Forge 带来的好处仍然可以超过最初的切换成本。

🌐 If you already have tooling for packaging and publishing your Electron app, the benefits associated with adopting Electron Forge can still outweigh the initial switching cost.

我们认为使用 Forge 有两个主要好处:

🌐 We believe there are two main benefits to using Forge:

  1. Forge 会在 Electron 支持新功能时立即获得新的应用构建特性。在这种情况下,你不需要自己接入新的工具支持,也不必等待其他包最终实现该支持后再升级。最近的案例包括 macOS 通用二进制ASAR 完整性检查
  2. Forge 的多包架构使其易于理解和扩展。 由于 Forge 由许多具有明确职责的小包组成,因此代码进程更容易理解。此外,Forge 可扩展的 API 设计意味着你可以为高级用例编写自己的附加构建逻辑,而不依赖提供的配置选项。有关编写自定义 Forge 插件、制造器和发布器的更多详细信息,请参阅文档中的 [扩展 Electron Forge] 部分。

重大变更

🌐 Breaking changes

Forge 6 在测试阶段已经花费了很长时间,其发布节奏逐渐放缓。然而,我们在 2022 年下半年加快了开发,并利用最近几次发布推进了一些最终的重大变更,为 v6.0.0 稳定版做准备。

🌐 Forge 6 has spent a long time in the beta phase, and its release cadence has gradually slowed down. However, we have accelerated development in the second half of 2022 and used the last few releases to push some final breaking changes before the v6.0.0 stable release.

如果你是 Electron Forge 6 测试版用户,请查看 v6.0.0 GitHub 发行说明 以获取最近测试版 (>=6.0.0-beta.65) 中重大更改的列表。

🌐 If you are an Electron Forge 6 beta user, see the v6.0.0 GitHub release notes for a list of breaking changes made in recent betas (>=6.0.0-beta.65).

完整的更改和提交列表可以在仓库的 CHANGELOG.md 中找到。

🌐 A complete list of changes and commits can be found in the repo's CHANGELOG.md.

提交你的反馈!

🌐 Submit your feedback!

告诉我们你的需求!Electron Forge 团队一直在努力打造更适合用户的项目。

🌐 Tell us what you need! The Electron Forge team is always looking to build the project to better suit its users.

你可以通过提交功能请求、发布问题或仅仅提供反馈来帮助我们改进 Electron Forge!你还可以加入我们的官方 Electron Discord 服务器,那里有专门的通道用于 Electron Forge 讨论。

🌐 You can help us improve Electron Forge by submitting feature requests, posting issues, or just letting us know your feedback! You can also join us in the official Electron Discord server, where there is a dedicated channel for Electron Forge discussion.

如果你想对 https://electronforge.io 上的 Forge 文档提供任何反馈,我们有一个 GitBook 实例,它与 electron-forge/electron-forge-docs 仓库同步。

🌐 If you want to give any feedback on the Forge docs at https://electronforge.io, we have a GitBook instance synced to the electron-forge/electron-forge-docs repo.