针对打包做相关调整

This commit is contained in:
2026-04-04 23:08:39 +08:00
parent e76b034d50
commit 8f4aa89249
7 changed files with 2458 additions and 1382 deletions

View File

@@ -7,10 +7,8 @@ import { MakerDMG } from '@electron-forge/maker-dmg';
import { VitePlugin } from '@electron-forge/plugin-vite';
import { FusesPlugin } from '@electron-forge/plugin-fuses';
import { FuseV1Options, FuseVersion } from '@electron/fuses';
// import MakerWix from '@electron-forge/maker-wix';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as esbuild from 'esbuild';
const config: ForgeConfig = {
packagerConfig: {
@@ -23,32 +21,25 @@ const config: ForgeConfig = {
rebuildConfig: {},
makers: [
new MakerSquirrel({
iconUrl: path.join(__dirname, 'public/logo.ico'), // 快捷方式的图标,需要在线的地址
iconUrl: path.join(__dirname, 'public/logo.ico'),
setupIcon: path.join(__dirname, 'public/logo.ico'),
setupExe: 'NianXX.exe',
// loadingGif: path.join(__dirname, 'public/loading.gif'), // 修改默认安装图片
}),
new MakerZIP({}, ['darwin']),
new MakerRpm({}),
new MakerDeb({}),
new MakerDMG({
name: 'NianXX',
icon: path.join(__dirname, 'public/logo.icns'),
}),
// new MakerWix({
// language: 2052,
// ui: {
// chooseDirectory: true,
// }
// }),
new MakerDMG(
(arch: string) => ({
name: `NianXX-${arch}`,
icon: path.join(__dirname, 'public/logo.icns'),
appPath: '',
} as any)
),
],
plugins: [
new VitePlugin({
// `build` can specify multiple entry builds, which can be Main process, Preload scripts, Worker process, etc.
// If you are familiar with Vite configuration, it will look really familiar.
build: [
{
// `entry` is just an alias for `build.lib.entry` in the corresponding file of `config`.
entry: 'src/main/main.ts',
config: 'vite.main.config.ts',
target: 'main',
@@ -66,8 +57,6 @@ const config: ForgeConfig = {
},
],
}),
// Fuses are used to enable/disable various Electron functionality
// at package time, before code signing the application
new FusesPlugin({
version: FuseVersion.V1,
[FuseV1Options.RunAsNode]: false,
@@ -84,17 +73,20 @@ const config: ForgeConfig = {
const dest = path.join(buildPath, '.vite', 'build', 'scripts');
await fs.ensureDir(dest);
// Bundle mjs scripts using esbuild
// 动态导入esbuild
const esbuildModule = await import('esbuild');
const esbuildBuild = esbuildModule.build;
const files = await fs.readdir(src);
for (const file of files) {
if (file.endsWith('.js')) {
await esbuild.build({
await esbuildBuild({
entryPoints: [path.join(src, file)],
outfile: path.join(dest, file),
bundle: true,
platform: 'node',
target: 'node24', // Adjust based on Electron version
external: [ 'electron' ], // Exclude electron and playwright dependencies from bundling
target: 'node24',
external: [ 'electron' ],
format: 'cjs',
});
} else {
@@ -102,7 +94,6 @@ const config: ForgeConfig = {
}
}
// Force playwright into the packaged node_modules since Forge Vite plugin ignores it
const playwrightSrc = path.join(__dirname, 'node_modules', 'playwright');
const playwrightDest = path.join(buildPath, 'node_modules', 'playwright');
if (await fs.pathExists(playwrightSrc)) {
@@ -124,10 +115,9 @@ const config: ForgeConfig = {
await fs.copy(chromiumBidiSrc, chromiumBidiDest);
}
// Force bytenode into the packaged node_modules since Forge Vite plugin ignores it
const bytenodeSrc = path.join(__dirname, 'node_modules', 'bytenode');
const bytenodeDest = path.join(buildPath, 'node_modules', 'bytenode');
if (await fs.pathExists(bytenodeSrc)) {
await fs.ensureDir(path.join(buildPath, 'node_modules'));
await fs.copy(bytenodeSrc, bytenodeDest);
@@ -145,6 +135,7 @@ const config: ForgeConfig = {
},
async postPackage(_forgeConfig, options) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const electronVersion = require('electron/package.json').version;
const nodeVersion = process.version;
const versionData = {
@@ -170,6 +161,7 @@ const config: ForgeConfig = {
},
async postMake(_forgeConfig, outputs) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const electronVersion = require('electron/package.json').version;
const nodeVersion = process.version;
const versionData = {