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 要使用Forge CLI,请将@electron-forge/cli
module into your project as a devDependency. @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.所有标志都是可选的。
--template | ||
--copy-ci-files | N/A |
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. Package
、Make
和Publish
命令是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.所有标志都是可选的。
--arch | x64 | |
--platform | mas |
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 如果不需要在Make运行之间重新打包应用程序,请使用--skip-package
flag.--skip-package
标志。
Options选项
All flags are optional.所有标志都是可选的。
--arch | x64 | "ia32" 、"x64" 、"armv7l" 、"arm 64" 、"universal" 或"mips64el" 。 |
--platform | mas | "host" 平台)。 |
--targets | @electron-forge/maker-deb . @electron-forge/maker-deb 。 | |
--skip-package | N/A |
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.所有标志都是可选的。
--target | ||
--dry-run | N/A | |
--from-dry-run | N/A |
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 此命令将以dev模式启动您的应用程序,electron
binary in the given directory (defaults to .
).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.所有标志都是可选的。
--app-path | . ). ) | |
--enable-logging | N/A | |
--run-as-node | N/A | |
--inspect-electron | N/A | |
-- | -- --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 Forge CLI应该适合大多数用例,但我们确实公开了@electron-forge/core
package for programmatic command usage.@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文档。