This article brings you a detailed introduction to electron-builder packaging. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
When developing electron client programs, packaging is an unavoidable problem. Let me share some insights based on my experience at work and my current understanding of electron-builder
.
Basic concepts
Definition of official website
A complete solution to package and build a ready for distribution Electron app for macOS, Windows and Linux with “auto update” support out of the box.This article about the basic parts of electron and electron-builder has been skipped. If you are interested, you can read this article
How to use
The use and configuration of builder is very simple
There are two ways to configure builder
Configure and use it directly in package.json (more commonly used, we will focus on this below)
Specify the electron-builder.yml file
The demo address will be given at the end of the article (electron in the demo project uses version V2.0.7, and currently the higher version is version 2.0.8).
The following is a simple annotated configuration in package.js
Basic configuration
"build": { // 这里是electron-builder的配置 "productName":"xxxx",//项目名 这也是生成的exe文件的前缀名 "appId": "com.xxx.xxxxx",//包名 "copyright":"xxxx",//版权 信息 "directories": { // 输出文件夹 "output": "build" }, // windows相关的配置 "win": { "icon": "xxx/icon.ico"//图标路径 } }
In the configuration file After adding the above files, you can package it into a simple folder. The folder is definitely not what we want. Next we will continue to talk about other configurations.
Packaging target configuration
If you want to package it into an installation program, we have two ways,
Use the NSIS tool to package our folder again and package it into exe
Package it directly into exe through nsis of electron-builder. The configuration is as follows
"win": { // 更改build下选项 "icon": "build/icons/aims.ico", "target": [ { "target": "nsis" // 我们要的目标安装包 } ] },
Other platform configuration
"dmg": { // macOSdmg "contents": [ ... ] }, "mac": { // mac "icon": "build/icons/icon.icns" }, "linux": { // linux "icon": "build/icons" }
##nsis configuration
"nsis": { "oneClick": false, // 是否一键安装 "allowElevation": true, // 允许请求提升。 如果为false,则用户必须使用提升的权限重新启动安装程序。 "allowToChangeInstallationDirectory": true, // 允许修改安装目录 "installerIcon": "./build/icons/aaa.ico",// 安装图标 "uninstallerIcon": "./build/icons/bbb.ico",//卸载图标 "installerHeaderIcon": "./build/icons/aaa.ico", // 安装时头部图标 "createDesktopShortcut": true, // 创建桌面图标 "createStartMenuShortcut": true,// 创建开始菜单图标 "shortcutName": "xxxx", // 图标名称 "include": "build/script/installer.nsh", // 包含的自定义nsis脚本 这个对于构建需求严格得安装过程相当有用。 "script" : "build/script/installer.nsh" // NSIS脚本的路径,用于自定义安装程序。 默认为build / installer.nsi },About
include and
script Which one to choose?
include configuration. If you need a cool installation process , it is recommended to use
script for complete customization.
NSIS is very powerful for processing installation packages. But it is no easier to learn than a high-level language. The secrets need to be explored by yourselves
- NSIS Basics
- NSIS Packaging Script basics
- Sample script
- NSIS Forum
- About operation System configuration
electron-builder --ia32 // 32位 electron-builder // 64位(默认)Configuration in nsis
"win": { "icon": "build/icons/aims.ico", "target": [ { "target": "nsis", "arch": [ // 这个意思是打出来32 bit + 64 bit的包,但是要注意:这样打包出来的安装包体积比较大,所以建议直接打32的安装包。 "x64", "ia32" ] } ] }
- Update configuration
lastest.yamlconfiguration file
"publish": [ { "provider": "generic", // 服务器提供商 也可以是GitHub等等 "url": "http://xxxxx/" // 服务器地址 } ],
Complete configuration
Basically available complete configuration"build": { "productName":"xxxx",//项目名 这也是生成的exe文件的前缀名 "appId": "com.leon.xxxxx",//包名 "copyright":"xxxx",//版权 信息 "directories": { // 输出文件夹 "output": "build" }, "nsis": { "oneClick": false, // 是否一键安装 "allowElevation": true, // 允许请求提升。 如果为false,则用户必须使用提升的权限重新启动安装程序。 "allowToChangeInstallationDirectory": true, // 允许修改安装目录 "installerIcon": "./build/icons/aaa.ico",// 安装图标 "uninstallerIcon": "./build/icons/bbb.ico",//卸载图标 "installerHeaderIcon": "./build/icons/aaa.ico", // 安装时头部图标 "createDesktopShortcut": true, // 创建桌面图标 "createStartMenuShortcut": true,// 创建开始菜单图标 "shortcutName": "xxxx", // 图标名称 "include": "build/script/installer.nsh", // 包含的自定义nsis脚本 }, "publish": [ { "provider": "generic", // 服务器提供商 也可以是GitHub等等 "url": "http://xxxxx/" // 服务器地址 } ], "files": [ "dist/electron/**/*" ], "dmg": { "contents": [ { "x": 410, "y": 150, "type": "link", "path": "/Applications" }, { "x": 130, "y": 150, "type": "file" } ] }, "mac": { "icon": "build/icons/icon.icns" }, "win": { "icon": "build/icons/aims.ico", "target": [ { "target": "nsis", "arch": [ "ia32" ] } ] }, "linux": { "icon": "build/icons" } }
Command line parameters (CLI)
Commands(command ):electron-builder build 构建命名 [default] electron-builder install-app-deps 下载app依赖 electron-builder node-gyp-rebuild 重建自己的本机代码 electron-builder create-self-signed-cert 为Windows应用程序创建自签名代码签名证书 electron-builder start 使用electronic-webpack在开发模式下运行应用程序(须臾要electron-webpack模块支持)Building(Building parameters):
--mac, -m, -o, --macos Build for macOS, [array] --linux, -l Build for Linux [array] --win, -w, --windows Build for Windows [array] --x64 Build for x64 (64位安装包) [boolean] --ia32 Build for ia32(32位安装包) [boolean] --armv7l Build for armv7l [boolean] --arm64 Build for arm64 [boolean] --dir Build unpacked dir. Useful to test. [boolean] --prepackaged, --pd 预打包应用程序的路径(以可分发的格式打包) --projectDir, --project 项目目录的路径。 默认为当前工作目录。 --config, -c 配置文件路径。 默认为`electron-builder.yml`(或`js`,或`js5`)Publishing(Publishing):
--publish, -p 发布到GitHub Releases [choices: "onTag", "onTagOrDraft", "always", "never", undefined]
Deprecated(Deprecated ):
--draft 请改为在GitHub发布选项中设置releaseType [boolean] --prerelease 请改为在GitHub发布选项中设置releaseType [boolean] --platform 目标平台 (请更改为选项 --mac, --win or --linux) [choices: "mac", "win", "linux", "darwin", "win32", "all", undefined] --arch 目标arch (请更改为选项 --x64 or --ia32) [choices: "ia32", "x64", "armv7l", "arm64", "all", undefined]Other(other):
--help Show help [boolean] --version Show version number [boolean]Examples(examples):
electron-builder -mwl 为macOS,Windows和Linux构建(同时构建) electron-builder --linux deb tar.xz 为Linux构建deb和tar.xz electron-builder -c.extraMetadata.foo=bar 将package.js属性`foo`设置为`bar` electron-builder --config.nsis.unicode=false 为NSIS配置unicode选项TargetConfiguration(build target configuration):
target: String - 目标名称,例如snap. arch “x64” | “ia32” | “armv7l” | “arm64”> | “x64” | “ia32” | “armv7l” | “arm64” -arch支持列表
Summary
electron-builder is a simple and powerful library. Anyway, I’m very impressedThe above is the detailed content of Detailed introduction to electron-builder packaging. For more information, please follow other related articles on the PHP Chinese website!

To build a website with powerful functions and good user experience, HTML alone is not enough. The following technology is also required: JavaScript gives web page dynamic and interactiveness, and real-time changes are achieved by operating DOM. CSS is responsible for the style and layout of the web page to improve aesthetics and user experience. Modern frameworks and libraries such as React, Vue.js and Angular improve development efficiency and code organization structure.

Boolean attributes are special attributes in HTML that are activated without a value. 1. The Boolean attribute controls the behavior of the element by whether it exists or not, such as disabled disable the input box. 2.Their working principle is to change element behavior according to the existence of attributes when the browser parses. 3. The basic usage is to directly add attributes, and the advanced usage can be dynamically controlled through JavaScript. 4. Common mistakes are mistakenly thinking that values need to be set, and the correct writing method should be concise. 5. The best practice is to keep the code concise and use Boolean properties reasonably to optimize web page performance and user experience.

HTML code can be cleaner with online validators, integrated tools and automated processes. 1) Use W3CMarkupValidationService to verify HTML code online. 2) Install and configure HTMLHint extension in VisualStudioCode for real-time verification. 3) Use HTMLTidy to automatically verify and clean HTML files in the construction process.

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools
