Skip to main content

Electron Forge 6 介绍

· 13 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 应用。

¥Electron Forge is a tool for packaging and distributing Electron applications. It unifies Electron's build tooling ecosystem into a single extensible interface so that anyone can jump right into making Electron apps.

亮点功能包括:

¥Highlight features include:

  • 📦 应用打包和代码签名

    ¥📦 Application packaging and code signing

  • 🚚 可在 Windows、macOS 和 Linux 上自定义的安装程序(DMG、deb、MSI、PKG、AppX 等)

    ¥🚚 Customizable installers on Windows, macOS, and Linux (DMG, deb, MSI, PKG, AppX, etc.)

  • ☁️ 云提供商(GitHub、S3、Bitbucket 等)的自动化发布流程

    ¥☁️ Automated publishing flow for cloud providers (GitHub, S3, Bitbucket, etc.)

  • ⚡ 易于使用的 webpack 和 TypeScript 样板模板

    ¥⚡️ Easy-to-use boilerplate templates for webpack and TypeScript

  • ⚙️ 原生 Node.js 模块支持

    ¥⚙️ Native Node.js module support

  • 🔌 可扩展的 JavaScript 插件 API

    ¥🔌 Extensible JavaScript plugin API

进一步阅读

访问 为何选择 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.

不要安装错误的软件包

对于 Electron Forge 5 及以下版本,已发布到 npm 上的 electron-forge 软件包中。从 v6 重写版本开始,Forge 的结构将改为一个包含许多较小项目的 monorepo 项目。

¥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;

    ¥enhancing local dev flow with webpack-dev-server, including support for HMR in the renderer;

  • 在应用打包之前处理 webpack 包的构建逻辑;and

    ¥handling build logic for webpack bundles before application packaging; and

  • 在 Webpack 打包过程中添加对原生 Node 模块的支持。

    ¥adding support for Native Node modules in the webpack bundling process.

如果你需要 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 完整性检查

    ¥Forge receives new features for application building as soon as they are supported in Electron. In this case, you won't need to wire in new tooling support yourself, or wait for that support to be eventually implemented by other packages before upgrading. For recent examples, see macOS universal binaries and ASAR integrity checking.

  2. Forge 的多包架构使其易于理解和扩展。由于 Forge 由许多职责明确的小型软件包组成,因此更容易遵循代码流程。此外,Forge 的可扩展 API 设计意味着你可以编写自己的额外构建逻辑,而无需使用提供的配置选项来处理高级用例。有关编写自定义 Forge 插件、创建器和发布器的更多详细信息,请参阅文档的 扩展 Electron Forge 部分。

    ¥Forge's multi-package architecture makes it easy to understand and extend. Since Forge is made up of many smaller packages with clear responsibilities, it is easier to follow code flow. In addition, Forge's extensible API design means that you can write your own additional build logic separate from the provided configuration options for advanced use cases. For more details on writing custom Forge plugins, makers, and publishers, see the Extending Electron Forge section of the docs.

重大变更

¥Breaking changes

Forge 6 已在 Beta 阶段进行了很长时间的测试,其发布节奏也逐渐放缓。但是,我们在 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.

你可以通过提交功能请求、发布 issues 或仅仅告诉我们你的反馈来帮助我们改进 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 文档提供任何反馈,我们有一个已同步到 electron-forge/electron-forge-docs 代码库的 GitBook 实例。

¥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.