fix(stage-tamagotchi): __dirname issue caused by badly overridden electron-vite config
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user