diff --git a/electron-builder.json5 b/electron-builder.json5 index cc2fca2..3ff2bfe 100644 --- a/electron-builder.json5 +++ b/electron-builder.json5 @@ -5,18 +5,19 @@ "$schema": "https://raw.githubusercontent.com/electron-userland/electron-builder/master/packages/app-builder-lib/scheme.json", "appId": "YourAppID", "asar": true, + "productName": "YourAppName", "directories": { "output": "release/${version}" }, "files": [ - "dist-electron", - "dist" + "dist", + "dist-electron" ], "mac": { - "artifactName": "${productName}_${version}.${ext}", "target": [ "dmg" - ] + ], + "artifactName": "${productName}-Mac-${version}-Installer.${ext}" }, "win": { "target": [ @@ -27,12 +28,18 @@ ] } ], - "artifactName": "${productName}_${version}.${ext}" + "artifactName": "${productName}-Windows-${version}-Setup.${ext}" }, "nsis": { "oneClick": false, "perMachine": false, "allowToChangeInstallationDirectory": true, "deleteAppDataOnUninstall": false + }, + "linux": { + "target": [ + "AppImage" + ], + "artifactName": "${productName}-Linux-${version}.${ext}" } } diff --git a/vite.config.ts b/vite.config.ts index fd60e80..4d136f0 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,6 +3,7 @@ import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import electron from 'vite-plugin-electron' import renderer from 'vite-plugin-electron-renderer' +import { notBundle } from 'vite-plugin-electron/plugin' import pkg from './package.json' // https://vitejs.dev/config/ @@ -18,13 +19,13 @@ export default defineConfig(({ command }) => { vue(), electron([ { - // Main-Process entry file of the Electron App. + // Main process entry file of the Electron App. entry: 'electron/main/index.ts', - onstart(options) { + onstart({ startup }) { if (process.env.VSCODE_DEBUG) { console.log(/* For `.vscode/.debug.script.mjs` */'[startup] Electron App') } else { - options.startup() + startup() } }, vite: { @@ -33,17 +34,26 @@ export default defineConfig(({ command }) => { minify: isBuild, outDir: 'dist-electron/main', rollupOptions: { + // Some third-party Node.js libraries may not be built correctly by Vite, especially `C/C++` addons, + // we can use `external` to exclude them to ensure they work correctly. + // Others need to put them in `dependencies` to ensure they are collected into `app.asar` after the app is built. + // Of course, this is not absolute, just this way is relatively simple. :) external: Object.keys('dependencies' in pkg ? pkg.dependencies : {}), }, }, + plugins: [ + // This is just an option to improve build performance, it's non-deterministic! + // e.g. `import log from 'electron-log'` -> `const log = require('electron-log')` + isServe && notBundle(), + ], }, }, { entry: 'electron/preload/index.ts', - onstart(options) { - // Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete, + onstart({ reload }) { + // Notify the Renderer process to reload the page when the Preload scripts build is complete, // instead of restarting the entire Electron App. - options.reload() + reload() }, vite: { build: { @@ -54,10 +64,13 @@ export default defineConfig(({ command }) => { external: Object.keys('dependencies' in pkg ? pkg.dependencies : {}), }, }, + plugins: [ + isServe && notBundle(), + ], }, } ]), - // Use Node.js API in the Renderer-process + // Use Node.js API in the Renderer process renderer(), ], server: process.env.VSCODE_DEBUG && (() => {