-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix dev server does not restart on save (#544)
* Partially revert a179d5c: vite 6 breaks watch mode Also unlocks vitest from 2.1.6 - no requirement to be pinned to that version. Partially reverts: a179d5c * Replace launchdev script with vite plugin Similar to previous impl., but uses watch mode detection instead of script. * Convert launchdev.js script to playwright loader * Rename for clarity: vite.config.ts * Remove redundant code * Remove debug code
- Loading branch information
1 parent
a1d6b6d
commit 4828924
Showing
11 changed files
with
349 additions
and
413 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { PluginOption } from 'vite'; | ||
import { spawn, type ChildProcess } from 'node:child_process'; | ||
import electronPath from 'electron'; | ||
|
||
/** | ||
* Loads the electron app whenever vite is loaded in watch mode. | ||
* Reloads the app after the bundle has been written and closed. | ||
* | ||
* Only operates in watch mode. | ||
*/ | ||
export function viteElectronAppPlugin(): PluginOption { | ||
const startApp = () => { | ||
electronApp = spawn(String(electronPath), ['--inspect=9223', '.'], { stdio: 'inherit' }); | ||
electronApp.addListener('exit', () => process.exit()); | ||
}; | ||
|
||
let electronApp: ChildProcess | null = null; | ||
|
||
return { | ||
name: 'Load Electron app in watch mode', | ||
apply: 'build', | ||
buildStart() { | ||
// Only operate in watch mode. | ||
if (this.meta.watchMode !== true || !electronApp) return; | ||
|
||
electronApp.removeAllListeners(); | ||
electronApp.kill('SIGINT'); | ||
electronApp = null; | ||
}, | ||
closeBundle() { | ||
// Only operate in watch mode. | ||
if (this.meta.watchMode === true) startApp(); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { build } from 'vite'; | ||
import electronPath from 'electron'; | ||
import { spawn } from 'node:child_process'; | ||
|
||
// Starts the app using the vite dev server, for use in playwright e2e testing. | ||
// Needs to be replaced with something more permanent at some point. | ||
|
||
/** @type {'production' | 'development'} */ | ||
const mode = (process.env.MODE = process.env.MODE || 'development'); | ||
|
||
/** @type {import('vite').LogLevel} */ | ||
const logLevel = 'warn'; | ||
|
||
/** @returns {import('vite').PluginOption} */ | ||
function runAppAfterBuild() { | ||
return { | ||
name: 'reload-app-on-main-package-change-a', | ||
writeBundle() { | ||
// CI-specific Electron launch args | ||
const args = ['--remote-debugging-port=9000', '--remote-allow-origins=http://127.0.0.1:9000', '.']; | ||
|
||
/** Spawn new electron process */ | ||
// eslint-disable-next-line @typescript-eslint/no-base-to-string | ||
const electronApp = spawn(String(electronPath), args, { stdio: 'inherit' }); | ||
|
||
/** Stops the watch script when the application has been quit */ | ||
electronApp.addListener('exit', () => process.exit()); | ||
}, | ||
}; | ||
} | ||
|
||
/** | ||
* Setup watcher for `main` package | ||
* On file changed it totally re-launch electron app. | ||
*/ | ||
function setupMainPackageWatcher() { | ||
return build({ | ||
mode, | ||
logLevel, | ||
configFile: 'vite.config.ts', | ||
plugins: [runAppAfterBuild()], | ||
}); | ||
} | ||
|
||
await setupMainPackageWatcher(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.