-
Notifications
You must be signed in to change notification settings - Fork 20
/
forge.config.ts
91 lines (89 loc) · 2.92 KB
/
forge.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import type { ForgeConfig } from '@electron-forge/shared-types';
import path from 'path'
import fsp from 'fs/promises'
import { downloadExtensions } from './build/download-extensions'
import { WebpackPlugin } from './build/webpack/ForgeWebpackPlugin'
import { buildAsar } from './build/build-asar'
import { signWinApp } from './build/util'
import { rebuild } from './build/rebuild'
import { MakerNsis } from './build/maker-nisi'
import { MakerZip } from './build/maker-zip'
import packageData from './package.json'
import productData from './product.json'
const config: ForgeConfig = {
packagerConfig: {
asar: false,
appVersion: packageData.version,
name: productData.productName,
appBundleId: productData.darwinBundleIdentifier,
icon: path.join(__dirname, './assets/icon/icon'),
extendInfo: {
CFBundleIconFile: 'icon.icns',
},
ignore: (file: string) => {
if (!file) return false;
return !/^[/\\](out|extensions|package\.json|product\.json)($|[/\\]).*$/.test(file);
},
prune: false,
afterFinalizePackageTargets: [
async (targets, done) => {
for (const target of targets) {
await rebuild({ arch: target.arch })
await buildAsar(path.resolve(`out/asar/${target.arch}`))
}
done()
}
],
afterCopy: [
async (appPath, electronVersion, pPlatform, pArch, done) => {
const asarDir = path.join(appPath, 'out/asar')
const files = await fsp.readdir(path.join(asarDir, pArch))
for (const filename of files) {
await fsp.rename(path.join(asarDir, pArch, filename), path.join(appPath, filename))
}
await fsp.rm(asarDir, { recursive: true })
done()
}
],
afterComplete: [
async (finalPath, electronVersion, pPlatform, pArch, done) => {
if (process.env.MAC_NOTARIZE_SCRIPT) {
const mod = await import(process.env.MAC_NOTARIZE_SCRIPT)
const fn = typeof mod === 'object' && mod && mod.default ? mod.default : mod;
if (typeof fn === 'function') {
await fn(path.join(finalPath, `${productData.productName}.app`), productData.darwinBundleIdentifier)
}
}
done()
}
],
extraResource: [
path.join(__dirname, './assets/app-update.yml'), // for electron-updater
],
...(process.env.WINDOWS_SIGN_TOOL_PATH ? ({
windowsSign: {
hookFunction: file => signWinApp(file)
},
}) : null),
...(process.env.OSX_SIGN_IDENTITY ? {
osxSign: {
identity: process.env.OSX_SIGN_IDENTITY,
},
} : null),
},
outDir: 'dist',
// @electron/rebuild 不支持 node-gyp 10,手动构建,跳过 forge 的自动构建
rebuildConfig: {
onlyModules: [],
},
makers: [new MakerNsis(), new MakerZip()],
plugins: [
new WebpackPlugin({}),
],
hooks: {
generateAssets: async () => {
await downloadExtensions();
},
},
};
export default config;