diff --git a/apps/stage-tamagotchi/electron.vite.config.ts b/apps/stage-tamagotchi/electron.vite.config.ts index 5206516fd..cd52643ac 100644 --- a/apps/stage-tamagotchi/electron.vite.config.ts +++ b/apps/stage-tamagotchi/electron.vite.config.ts @@ -19,22 +19,31 @@ import { defineConfig } from 'electron-vite' const stageUIAssetsRoot = resolve(join(import.meta.dirname, '..', '..', 'packages', 'stage-ui', 'src', 'assets')) const sharedCacheDir = resolve(join(import.meta.dirname, '..', '..', '.cache')) -export default defineConfig({ +const config = defineConfig({ main: { - plugins: [Info()], - build: { - rolldownOptions: { - output: { - // https://github.com/lobehub/lobehub/blob/6ecba929b738e1259e15d17e7643941e015324ee/apps/desktop/electron.vite.config.ts#L54 - // Prevent debug package from being bundled into index.js to avoid side-effect pollution - manualChunks(id) { - if (id.includes('node_modules/debug')) { - return 'vendor-debug' - } - }, + plugins: [ + Info(), + { + // To replace `build.rolldownOptions`, as electron-vite still uses the deprecated + // `rollupOptions`, using `rollupOptions` and `rolldownOptions` at the same + // time may lead to unexpected merge results. Using `rollupOptions` to manipulate + // `manualChunks` also did not work. Therefore, it was transformed into a plugin + // declaration with the recommended `codeSplitting` option. + name: 'manual-chunks', + outputOptions(options) { + options.codeSplitting = { + groups: [{ + name(moduleId) { + if (moduleId.includes('node_modules/debug')) { + return 'vendor-debug' + } + }, + }], + } + return options }, }, - }, + ], }, preload: { build: { @@ -196,3 +205,7 @@ export default defineConfig({ ], }, }) + +console.log(config.main?.build?.rolldownOptions) + +export default config diff --git a/apps/stage-tamagotchi/src/main/index.ts b/apps/stage-tamagotchi/src/main/index.ts index 2daf87189..e9839453c 100644 --- a/apps/stage-tamagotchi/src/main/index.ts +++ b/apps/stage-tamagotchi/src/main/index.ts @@ -1,4 +1,6 @@ +import { dirname } from 'node:path' import { env, platform } from 'node:process' +import { fileURLToPath } from 'node:url' import { electronApp, optimizer } from '@electron-toolkit/utils' import { Format, LogLevel, setGlobalFormat, setGlobalLogLevel, useLogg } from '@guiiai/logg' @@ -32,7 +34,7 @@ import { setupWidgetsWindowManager } from './windows/widgets' // manage events within eventa's context system. ipcMain.setMaxListeners(100) -setElectronMainDirname(__dirname) +setElectronMainDirname(dirname(fileURLToPath(import.meta.url))) setGlobalFormat(Format.Pretty) setGlobalLogLevel(LogLevel.Log) setupDebugger() diff --git a/apps/stage-tamagotchi/src/main/windows/about/index.ts b/apps/stage-tamagotchi/src/main/windows/about/index.ts index fd0321b6a..cc3a84864 100644 --- a/apps/stage-tamagotchi/src/main/windows/about/index.ts +++ b/apps/stage-tamagotchi/src/main/windows/about/index.ts @@ -22,7 +22,7 @@ export function setupAboutWindowReusable(params: { autoUpdater: AutoUpdater }) { minimizable: false, icon, webPreferences: { - preload: join(__dirname, '../preload/index.mjs'), + preload: join(getElectronMainDirname(), '../preload/index.mjs'), sandbox: false, }, }) diff --git a/apps/stage-tamagotchi/src/main/windows/caption/index.ts b/apps/stage-tamagotchi/src/main/windows/caption/index.ts index a3b1c91e6..80d2a960c 100644 --- a/apps/stage-tamagotchi/src/main/windows/caption/index.ts +++ b/apps/stage-tamagotchi/src/main/windows/caption/index.ts @@ -111,7 +111,7 @@ function createCaptionWindow(options?: BrowserWindowConstructorOptions) { show: false, icon, webPreferences: { - preload: join(__dirname, '../preload/index.mjs'), + preload: join(getElectronMainDirname(), '../preload/index.mjs'), sandbox: false, }, // Thanks to [@HeartArmy](https://github.com/HeartArmy) for the tip implementation. diff --git a/apps/stage-tamagotchi/src/main/windows/chat/index.ts b/apps/stage-tamagotchi/src/main/windows/chat/index.ts index e2dfd4c61..04a3b32c0 100644 --- a/apps/stage-tamagotchi/src/main/windows/chat/index.ts +++ b/apps/stage-tamagotchi/src/main/windows/chat/index.ts @@ -23,7 +23,7 @@ export function setupChatWindowReusableFunc(params: { show: false, icon, webPreferences: { - preload: join(__dirname, '../preload/index.mjs'), + preload: join(getElectronMainDirname(), '../preload/index.mjs'), sandbox: false, }, }) diff --git a/apps/stage-tamagotchi/src/main/windows/devtools/index.ts b/apps/stage-tamagotchi/src/main/windows/devtools/index.ts index c08d0255d..4b9973477 100644 --- a/apps/stage-tamagotchi/src/main/windows/devtools/index.ts +++ b/apps/stage-tamagotchi/src/main/windows/devtools/index.ts @@ -27,7 +27,7 @@ export function setupDevtoolsWindow(): DevtoolsWindowManager { show: false, icon, webPreferences: { - preload: join(__dirname, '../preload/index.mjs'), + preload: join(getElectronMainDirname(), '../preload/index.mjs'), // Preload exposes Electron APIs and needs Node access. sandbox: false, }, diff --git a/apps/stage-tamagotchi/src/main/windows/inlay/index.ts b/apps/stage-tamagotchi/src/main/windows/inlay/index.ts index e27b250e4..71a86013e 100644 --- a/apps/stage-tamagotchi/src/main/windows/inlay/index.ts +++ b/apps/stage-tamagotchi/src/main/windows/inlay/index.ts @@ -18,7 +18,7 @@ export async function setupInlayWindow() { show: false, icon, webPreferences: { - preload: join(__dirname, '../preload/index.mjs'), + preload: join(getElectronMainDirname(), '../preload/index.mjs'), sandbox: false, }, ...spotlightLikeWindowConfig(), diff --git a/apps/stage-tamagotchi/src/main/windows/notice/index.ts b/apps/stage-tamagotchi/src/main/windows/notice/index.ts index b0e8f5aab..970ed37a2 100644 --- a/apps/stage-tamagotchi/src/main/windows/notice/index.ts +++ b/apps/stage-tamagotchi/src/main/windows/notice/index.ts @@ -28,7 +28,7 @@ export function setupNoticeWindowManager(): NoticeWindowManager { show: false, icon, webPreferences: { - preload: join(__dirname, '../preload/index.mjs'), + preload: join(getElectronMainDirname(), '../preload/index.mjs'), sandbox: false, }, }) diff --git a/apps/stage-tamagotchi/src/main/windows/settings/index.ts b/apps/stage-tamagotchi/src/main/windows/settings/index.ts index 7b5d15018..34e4f0187 100644 --- a/apps/stage-tamagotchi/src/main/windows/settings/index.ts +++ b/apps/stage-tamagotchi/src/main/windows/settings/index.ts @@ -29,7 +29,7 @@ export function setupSettingsWindowReusableFunc(params: { show: false, icon, webPreferences: { - preload: join(__dirname, '../preload/index.mjs'), + preload: join(getElectronMainDirname(), '../preload/index.mjs'), sandbox: false, }, }) diff --git a/apps/stage-tamagotchi/src/main/windows/widgets/index.ts b/apps/stage-tamagotchi/src/main/windows/widgets/index.ts index 8cb417fa5..5488da43b 100644 --- a/apps/stage-tamagotchi/src/main/windows/widgets/index.ts +++ b/apps/stage-tamagotchi/src/main/windows/widgets/index.ts @@ -58,7 +58,7 @@ function createWidgetsWindow() { show: false, icon, webPreferences: { - preload: join(__dirname, '../preload/index.mjs'), + preload: join(getElectronMainDirname(), '../preload/index.mjs'), sandbox: false, }, // Top-level overlay style like other overlay windows