wix - 我无法运行 electron-wix-msi
问题描述
我在使用 webpack 将电子项目打包为 MSI 安装程序时遇到了问题。我遇到了electron-wix-msi包。它是伟大的 WIX 工具包的包装器。优点是,它更像 Windows。
但是,文档不清楚,不足以让它立即运行。最后我明白了,想在这里分享步骤。
解决方案
我使用 TypeScript 进行开发,并安装了所有部件,包括 MSI。
这仅适用于 Windows 用户。该过程描述了 Windows 安装程序 (MSI) 的创建。
- 按照文档中的说明安装 Wix Toolkit
- 将candle.exe和light.exe的路径添加到路径变量中,即“C:\Program Files (x86)\WiX Toolset v3.11\bin”。检查是否在提示符处输入“candle”,candle.exe 是否会执行。
- 在文件夹build中创建安装文件为make-msi.ts(只是一个建议,任何路径都可以):
import * as msi from 'electron-wix-msi';
import * as path from 'path';
// Step 1: Instantiate the MSICreator
const msiCreator = new msi.MSICreator({
appDirectory: path.resolve('release/win-unpacked'), // result from electron-builder
description: 'Some text',
exe: 'MyExe',
name: 'MyExe',
manufacturer: 'Joerg Krause',
version: '0.5.0',
language: 1033,
arch: 'x86',
outputDirectory: path.resolve('release/msi/')
});
async function createMsi() {
// Step 2: Create a .wxs template file
await msiCreator.create();
// Step 3: Compile the template to a .msi file
await msiCreator.compile();
}
console.log('Invoke MSI Builder');
createMsi();
release/win-unpacked是electron-builder的输出。
- 在同一文件夹build中添加具有适当设置的tsconfig.json:
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"sourceMap": true,
"lib": [
"es2018",
"es5",
"dom"
],
"experimentalDecorators": true,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"removeComments": false,
"outDir": "js",
"typeRoots": [
"../node_modules/@types",
]
}
}
- 检查文件夹build中的两个文件
- 将这样的命令添加
npm run
到您的package.json:
cd build && tsc && cd .. && node build/js/make-msi.js
我的整个脚本块如下所示:
"scripts": {
"dev": "tsc win.ts --outDir ./dist && cross-env NODE_ENV=dev && npm run prev",
"build": "rimraf ./dist && webpack",
"start": "rimraf ./dist && webpack && electron .",
"prev": "electron .",
"test": "jest",
"msi": "cd build && tsc && cd .. && node build/js/make-msi.js",
"pack": "npm run build && rimraf ./release && build --dir && npm run msi",
"dist": "build"
}
这会将 TypeScript 编译成 ES 并使用npm run msi
. 一段时间后,您就有了 MSI。
此外,我使用electron-builder而不是electron-packager取得了更大的成功。
对于那些想要获得更多的人,我的设置是这样的:
- 我用 HTML 5 API(没有 React/Angular 左右)编写我的应用程序。我真的可以为中小型应用程序推荐这个。
- 我将 TypeScript 3 用于所有编码内容
- 我将 SASS 用于所有 CSS 内容
- 使用webpack进行编译、优化和打包
- 我使用电子生成器捆绑
- 我使用上面描述的过程来制作一个 Windows 包。
推荐阅读
- scala - 使用猫嵌套映射一系列期货?
- scala - 从 Scala 期货中获取价值
- node.js - 来自 URL 源的图像与 Express 服务器中的本地文件
- javascript - 删除 iframe 会影响某些浏览器中的会话历史记录,但不会影响 Chrome
- c++ - 如何避免 std 库中的无效重载?
- swagger - 用于复杂嵌套 JSON 的 Swagger 文档
- python - 在减少重复代码、配置和存储方面,编写自定义 Keras 层的最佳实践是什么?
- r - 通过R中的多个模式子集栅格堆栈
- azure - Azure Devops 如何在任务中获取安全变量值
- snowflake-cloud-data-platform - 如何从 Snowflake 中的所有模式中查找存储过程和函数?