CLI

How to use the command line interface (CLI) commands for Electron Forge如何使用Electron Forge的命令行界面(CLI)命令

Overview概述

Forge's CLI is the main way to run Electron Forge commands. Forge的CLI是运行Electron Forge命令的主要方式。It consists of a thin wrapper for its core API. Configuration for these commands is done through your Forge configuration object.它包含一个用于其核心API的薄包装器。这些命令的配置是通过Forge配置对象完成的。

If you want to use the core API programmatically, see the Programmatic usage section below.如果您想以编程方式使用核心API,请参阅下面的编程用法部分。

Forge's CLI uses comma-separated value strings to pass multiple arguments into a single flag. Forge的CLI使用逗号分隔的值字符串将多个参数传递到单个标志中。Depending on your terminal, these comma-separated values may need to be enclosed in quotation marks.根据您的终端,这些逗号分隔的值可能需要用引号括起来。

Installation安装

To use the Forge CLI, install the @electron-forge/cli module into your project as a devDependency. 要使用Forge CLI,请将@electron-forge/cli模块作为devDependency安装到您的项目中。If you're using the create-electron-app script, this module will already be installed for you.如果您使用的是create-electron-app应用程序脚本,则此模块已为您安装。

npm install --save-dev @electron-forge/cli

Bootstrap commands引导命令

These commands help you get started with Forge. If you're just getting started with Electron Forge, we recommend you follow the Getting Started or Importing an Existing Project guides.这些命令可以帮助您开始使用Forge。如果您刚开始使用Electron Forge,我们建议您遵循起步导入现有项目指南。

Init

We recommend using the create-electron-app script (which uses this command) to get started rather than running Init directly.我们建议使用create-electron-app脚本(使用此命令)开始,而不是直接运行Init。

This command will initialize a new Forge-powered application in the given directory (defaults to ., the current directory).此命令将在给定目录(默认为.,即当前目录)中初始化一个新的Forge驱动的应用程序。

Please note if you want to use a non-builtin template, it must be installed globally before running the init command.请注意,如果要使用非内置模板,则必须在运行init命令之前全局安装该模板。

Options选项

All flags are optional.所有标志都是可选的。

Flag标志ValueDescription描述
--templateTemplate Name模板名称Name of the template to use to make this new app用于制作此新应用的模板的名称
--copy-ci-filesN/ASet if you want to copy templated CI files (coming soon)设置是否要复制模板CI文件(即将推出

Usage用法

npx electron-forge init --template=webpack

Import

This command will attempt to take an existing Electron app and make it compatible with Forge. 此命令将尝试使用现有的Electron应用程序,并使其与Forge兼容。Normally, this just creates a base Electron Forge configuration and adds the required dependencies.通常,这只是创建一个基本的Electron Forge配置并添加所需的依赖项。

Options选项

There are no options for the Import command.“导入”命令没有选项。

Usage用法

npx electron-forge import

Build commands生成命令

The Package, Make, and Publish commands are the three main steps of the Electron Forge build pipeline. PackageMakePublish命令是Electron Forge构建管道的三个主要步骤。Each step relies on the output of the previous one, so they are cascading by default (e.g. running publish will first run package then make.每个步骤都依赖于前一个步骤的输出,因此它们在默认情况下是级联的(例如,运行publish将首先运行package,然后再进行make

For more conceptual details, see the Build Lifecycle guide.有关更多概念性详细信息,请参阅构建生命周期指南。

Package

This command will package your application into a platform-specific executable bundle and put the result in a folder. 此命令将把您的应用程序打包到特定于平台的可执行捆绑包中,并将结果放在文件夹中。Please note that this does not make a distributable format. 请注意,这并不构成可分发的格式。To make proper distributables, please use the Make command.要制作正确的可分发文件,请使用make命令。

Options选项

All flags are optional.所有标志都是可选的。

Flag标志ValueDescription描述
--archArchitecture, e.g. 架构,例如。x64Target architecture to package for. Defaults to the host arch.要打包的目标体系结构。默认为host拱门。
--platformPlatform, e.g. 平台,例如。masTarget platform to package for. Defaults to the host platform.要打包的目标平台。默认为host平台。

Usage用法

# By default, the package command corresponds to a package npm script:
npm run package -- --arch="ia32"
# If there is no package script:
npx electron-forge package --arch="ia32"

Make

This command will make distributables for your application based on your Forge config and the parameters you pass in.该命令将根据您的Forge配置和传入的参数为您的应用程序提供可分发的内容。

If you do not need to repackage your application between Make runs, use the --skip-package flag.如果不需要在Make运行之间重新打包应用程序,请使用--skip-package标志。

Options选项

All flags are optional.所有标志都是可选的。

Flag标志ValueDescription描述
--archArchitecture, e.g. 架构,例如。x64Target architecture to make for. 目标架构。Defaults to the arch that you're running on (the "host" arch). 默认为您正在运行的拱门(“host”拱门)。Allowed values are: "ia32", "x64", "armv7l", "arm64", "universal", or "mips64el". 允许的值为:"ia32""x64""armv7l""arm 64""universal""mips64el"Multiple values should be comma-separated.多个值应以逗号分隔。
--platformPlatform, e.g. 平台,例如。masTarget platform to make for, please note you normally can only target platform X from platform X. 目标平台,请注意,您通常只能从X平台瞄准X平台。This defaults to the platform you're running on (the "host" platform).这默认为您运行的平台("host"平台)。
--targetsComma separated list of maker names制造商名称的逗号分隔列表Override your make targets for this run. 覆盖此跑步的make目标。The maker name is the full node module name, e.g. @electron-forge/maker-deb. 制造商名称是完整的节点模块名称,例如@electron-forge/maker-debBy default, the make targets used are the ones available and configured for the given platform.默认情况下,使用的make目标是针对给定平台可用和配置的目标。
--skip-packageN/ASet if you want to skip the packaging step, useful if you are running sequential makes and want to save time. 如果您想跳过打包步骤,请设置,如果您正在运行顺序生成并希望节省时间,则设置非常有用。By default, packaging is not skipped.默认情况下,不会跳过打包。

Usage用法

Basic usage:基本用法

# By default, the make command corresponds to a make npm script:
npm run make -- --arch="ia32"
# If there is no make script:
npx electron-forge make --arch="ia32"

Building for ia32 and x64 architectures:针对ia32和x64体系结构的构建:

npm run make -- --arch="ia32,x64"

Publish

This command will attempt to package, make, and publish the Forge application to the publish targets defined in your Forge config.此命令将尝试将Forge应用程序打包、制作并发布到Forge配置中定义的发布目标。

If you want to verify artifacts from the Make step before publishing, you can use the Dry Run options explained below.如果要在发布前验证“制作”步骤中的工件,可以使用下面解释的“干运行”选项。

Options选项

All flags are optional.所有标志都是可选的。

Flag标志ValueDescription描述
--targetComma separated list of publisher names以逗号分隔的发布者名称列表Override your publish targets for this run覆盖此跑步的发布目标
--dry-runN/ATriggers a publish dry run which saves state and doesn't upload anything触发发布试运行,保存状态并且不上载任何内容
--from-dry-runN/AAttempts to publish artifacts from any dry runs saved on disk尝试从磁盘上保存的任何试运行中发布工件

Usage用法

# By default, the publish command corresponds to a publish npm script:
npm run publish -- --from-dry-run
# If there is no publish script:
npx electron-forge publish -- --from-dry-run

Dev commands开发命令

Start

This command will launch your app in dev mode with the electron binary in the given directory (defaults to .).此命令将以dev模式启动您的应用程序,electron二进制文件位于给定目录中(默认为.)。

If you type rs (and hit enter) in the same terminal where you ran the start command, the running app will be terminated and restarted.如果您在运行启动命令的同一终端中键入rs(并点击回车),则正在运行的应用程序将被终止并重新启动。

Forge plugins can override this command to run custom development logic. For example, the Webpack Plugin runs a webpack-dev-server instance to provide live reloading and HMR.Forge插件可以覆盖此命令来运行自定义开发逻辑。例如,Webpack插件运行一个Webpack开发服务器实例,以提供实时重新加载和HMR。

Options选项

All flags are optional.所有标志都是可选的。

Flag标志ValueDescription描述
--app-pathPath to your app from the working directory工作目录中应用程序的路径Override the path to the Electron app to launch (defaults to .)覆盖要启动的Electron应用程序的路径(默认为.
--enable-loggingN/AEnable advanced logging. This will log internal Electron things启用高级日志记录。这将记录Electron内部的事情
--run-as-nodeN/ARun the Electron app as a Node.JS script将Electron应用程序作为Node.JS脚本运行
--inspect-electronN/ATriggers inspect mode on Electron to allow debugging the main process触发Electron上的检查模式,以允许调试主进程
--extra arguments额外的自变量Any additional arguments to pass to Electron or the app itself. 要传递给Electron或应用程序本身的任何其他参数。For example: 例如:-- --my-app-argument

Usage用法

# By default, the start command corresponds to a start npm script:
npm start --enable-logging
# if there is no start script
npx electron-forge start --enable-logging

Programmatic usage程序化用法

The Forge CLI should suit most use cases, but we do expose the @electron-forge/core package for programmatic command usage.Forge CLI应该适合大多数用例,但我们确实公开了@electron-forge/core包以供编程命令使用。

const { api } = require('@electron-forge/core');
​
const main = async () => {
  await api.package({
    // add package command options here
  });
};
​
main();

For more information, see the API documentation.有关更多信息,请参阅API文档