我在使用 webpack 将 Electron 项目打包为 MSI 安装程序时遇到了问题。我遇到了 Electron -wix-msi 包。它是伟大的 WIX 工具包的 package 器。优点是,它更像 Windows。
但是,文档不清楚,不足以使其立即运行。终于我明白了,想在这里分享步骤。
最佳答案
我使用 TypeScript 进行开发,并获得了所有部分的工作安装,包括 MSI。
This is for Windows users only. The process describes the creation of an Windows-Installer (MSI).
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 is the output from electron-builder.
{
"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",
]
}
}
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 构建器而不是 Electron package 器取得了更大的成功。
对于那些想要获得更多的人,我的设置是这样的:
关于wix - 我无法运行 electron-wix-msi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54537837/