electron从入门到弃坑

2020-03-02  本文已影响0人  是我拉叔

科学梯子自备



electron的安装

资料地址:https://github.com/electron/electron
https://github.com/electron/electron/blob/master/docs/tutorial/installation.md

Installation

To install prebuilt Electron binaries, use npm. The preferred method is to install Electron as a development dependency in your app:

npm install electron --save-dev [--save-exact]

The --save-exact flag is recommended for Electron prior to version 2, as it does not follow semantic versioning. As of version 2.0.0, Electron follows semver, so you don't need --save-exact flag. For info on how to manage Electron versions in your apps, see Electron versioning.

For more installation options and troubleshooting tips, see installation.

Quick start & Electron Fiddle

Use Electron Fiddle to build, run, and package small Electron experiments, to see code examples for all of Electron's APIs, and to try out different versions of Electron. It's designed to make the start of your journey with Electron easier.

Alternatively, clone and run the electron/electron-quick-start repository to see a minimal Electron app in action:

git clone https://github.com/electron/electron-quick-startcdelectron-quick-startnpm installnpm start

以上hello world完成,网上大部分教程到此。

程序想运行在操作系统上,还需要下面步骤

electron-packager进行打包

资料地址:https://github.com/electron/electron-packager

Installation

This module requires Node.js 10.0 or higher to run. On macOS/Linux, the unzip program is required. On Windows, both .NET Framework 4.5 or higher and Powershell 3 or higher are required.

#For use in npm scripts (recommended)
npm install electron-packager --save-dev
#For use from the CLI
npm install electron-packager -g

Building Windows apps from non-Windows platforms

Building an Electron app for the Windows target platform requires editing the Electron.exe file. Currently, Electron Packager uses node-rcedit to accomplish this. A Windows executable is bundled in that Node package and needs to be run in order for this functionality to work, so on non-Windows host platforms, Wine 1.6 or later needs to be installed. On macOS, it is installable via Homebrew.

上面这里涉及到 homebrew 的安装 和 wine 的安装,安装方法按链接官方地址自取。

From the Command Line

Running electron-packager from the command line has this basic form:

electron-packager <sourcedir> <appname> --platform=<platform> --arch=<arch> [optional flags...]

This will:

Find or download the correct release of Electron
Use that version of Electron to create a app in <out>/<appname>-<platform>-<arch> (this can be customized via an optional flag)

--platform and --arch can be omitted, in two cases:

If you specify --all instead, bundles for all valid combinations of target platforms/architectures will be created.
Otherwise, a single bundle for the host platform/architecture will be created.

上一篇 下一篇

猜你喜欢

热点阅读