Getting Started起步

Quickly scaffold an Electron project with a full build pipeline通过完整的管道快速构建Electron项目

Overview概述

Electron Forge is an all-in-one tool for packaging and distributing Electron applications. It combines many single-purpose packages to create a full build pipeline that works out of the box, complete with code signing, installers, and artifact publishing. Electron Forge是一款用于包装和分发Electron应用程序的一体化工具。它结合了许多单一用途的包来创建一个开箱即用的完整构建管道,包括代码签名、安装程序和工件发布。For advanced workflows, custom build logic can be added in the Forge lifecycle through its Plugin API. Custom build and storage targets can be handled by creating your own Makers and Publishers.对于高级工作流,可以通过其插件API在Forge生命周期中添加自定义构建逻辑。自定义构建和存储目标可以通过创建自己的制造商发布商来处理。

Creating a new app创建新应用

To get started with Electron Forge, we first need to initialize a new project with create-electron-app. 要开始使用Electron Forge,我们首先需要初始化一个带有create-electron-app的新项目。This script is a convenient wrapper around Forge's Init command.这个脚本是围绕Forge的Init命令的一个方便的包装器。

npm init electron-app@latest my-app

If you used the create-electron-app script before during Forge 6.0.0-beta, we recommend you uninstall the package globally before running the command again.如果您之前在Forge 6.0.0-beta期间使用过create-electron-app脚本,我们建议您在再次运行该命令之前全局卸载该包。

npm uninstall -g create-electron-app

Using templates使用模板

Forge's initialization scripts can add additional template code with the --template=[template-name] flag.Forge的初始化脚本可以添加带有--template=[template-name]标志的额外模板代码。

npm init electron-app@latest my-app -- --template=webpack

There are currently two first-party templates:目前有两个第一方模板:

Both of these templates are built around the Webpack Plugin, which bundles your JavaScript code for production and includes a dev server to provide a better development experience. 这两个模板都是围绕Webpack插件构建的,该插件将您的JavaScript代码捆绑在一起用于生产,并包括一个开发服务器,以提供更好的开发体验。The webpack-typescript template also wires up your project for TypeScript support.webpack-typescript模板还连接您的项目以获得typescript支持。

We highly recommend using these templates when initializing your app to take advantage of modern front-end JavaScript tooling.我们强烈建议在初始化应用程序时使用这些模板,以利用现代前端JavaScript工具。

To learn more about authoring your own templates for Electron Forge, check out the Writing Templates guide!要了解有关为Electron Forge编写自己的模板的更多信息,请查看编写模板指南!

Starting your app启动你的应用程序

You should now have a directory called my-app with all the files you need for a basic Electron app.你现在应该有一个名为my-app的目录,其中包含基本Electron应用程序所需的所有文件。

cd my-app
npm start

Building distributables构建可分配资产

So you've got an amazing application there, and you want to package it all up and share it with the world. 所以你有一个很棒的应用程序,你想把它打包并与世界分享。If you run the make script, Electron Forge will generate you platform specific distributables for you to share with everyone. 如果你运行make脚本,Electron Forge将为你生成特定于平台的可分发文件,供你与所有人共享。For more information on what kind of distributables you can make, check out the Makers documentation.有关您可以制作何种可分发文件的更多信息,请查看制造商文档。

npm run make

Publishing your app发布你的应用

Now you have distributables that you can share with your users. 现在,您可以与用户共享可分发的内容。If you run the publish script, Electron Forge will then publish the platform-specific distributables for you, using the publishing method of your choice. 如果您运行publish脚本,Electron Forge将使用您选择的发布方法为您发布特定于平台的可分发文件。For more information on what publishers we currently support, check out the Publishers documentation.有关我们目前支持的发布者的更多信息,请查看发布者文档。

npm run publish

Advanced Usage高级用法

Once you've got a basic app starting, building and publishing, it's time to add your custom configuration, which can be done in the forge.config.js file. 一旦你启动、构建和发布了一个基本的应用程序,就可以添加你的自定义配置了,这可以在forge.config.js文件中完成。Configuration options are specified in the Configuration Docs.配置选项在配置文档中指定。

You can also check out the documentation on some of our more advanced features like:您还可以查看我们一些更高级功能的文档,如: