refactor: use watch.mjs in .debug.script.mjs
This commit is contained in:
parent
1651b5dd2a
commit
9336e41591
|
@ -1,47 +1 @@
|
||||||
import fs from 'fs'
|
import '../scripts/watch.mjs?debug=vscode'
|
||||||
import path from 'path'
|
|
||||||
import { fileURLToPath } from 'url'
|
|
||||||
import { createRequire } from 'module'
|
|
||||||
import { build, createServer } from 'vite'
|
|
||||||
|
|
||||||
const pkg = createRequire(import.meta.url)('../package.json')
|
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
||||||
|
|
||||||
async function buildDebugApp() {
|
|
||||||
const server = await createServer({ configFile: 'packages/renderer/vite.config.ts' })
|
|
||||||
|
|
||||||
await server.listen()
|
|
||||||
|
|
||||||
await build({
|
|
||||||
configFile: 'packages/preload/vite.config.ts',
|
|
||||||
build: {
|
|
||||||
watch: true,
|
|
||||||
sourcemap: true,
|
|
||||||
},
|
|
||||||
mode: 'development',
|
|
||||||
})
|
|
||||||
|
|
||||||
await build({
|
|
||||||
configFile: 'packages/main/vite.config.ts',
|
|
||||||
build: {
|
|
||||||
watch: true,
|
|
||||||
sourcemap: true,
|
|
||||||
},
|
|
||||||
mode: 'development',
|
|
||||||
plugins: [{
|
|
||||||
name: 'electron-preload-watcher',
|
|
||||||
writeBundle() {
|
|
||||||
server.ws.send({ type: 'full-reload' })
|
|
||||||
},
|
|
||||||
}],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function writeEnvLocal() {
|
|
||||||
const envContent = Object.entries(pkg.env).map(([key, val]) => `${key}=${val}`)
|
|
||||||
fs.writeFileSync(path.join(__dirname, '.debug.env'), envContent.join('\n'))
|
|
||||||
}
|
|
||||||
|
|
||||||
// bootstrap
|
|
||||||
writeEnvLocal()
|
|
||||||
buildDebugApp()
|
|
|
@ -2,6 +2,9 @@ import { spawn } from 'child_process'
|
||||||
import { createServer, build } from 'vite'
|
import { createServer, build } from 'vite'
|
||||||
import electron from 'electron'
|
import electron from 'electron'
|
||||||
|
|
||||||
|
const query = new URLSearchParams(import.meta.url.split('?')[1])
|
||||||
|
const debug = query.has('debug')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {(server: import('vite').ViteDevServer) => Promise<import('rollup').RollupWatcher>}
|
* @type {(server: import('vite').ViteDevServer) => Promise<import('rollup').RollupWatcher>}
|
||||||
*/
|
*/
|
||||||
|
@ -15,17 +18,21 @@ function watchMain(server) {
|
||||||
VITE_DEV_SERVER_HOST: address.address,
|
VITE_DEV_SERVER_HOST: address.address,
|
||||||
VITE_DEV_SERVER_PORT: address.port,
|
VITE_DEV_SERVER_PORT: address.port,
|
||||||
})
|
})
|
||||||
|
/**
|
||||||
|
* @type {import('vite').Plugin}
|
||||||
|
*/
|
||||||
|
const startElectron = {
|
||||||
|
name: 'electron-main-watcher',
|
||||||
|
writeBundle() {
|
||||||
|
electronProcess && electronProcess.kill()
|
||||||
|
electronProcess = spawn(electron, ['.'], { stdio: 'inherit', env })
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
return build({
|
return build({
|
||||||
configFile: 'packages/main/vite.config.ts',
|
configFile: 'packages/main/vite.config.ts',
|
||||||
mode: 'development',
|
mode: 'development',
|
||||||
plugins: [{
|
plugins: [!debug && startElectron].filter(Boolean),
|
||||||
name: 'electron-main-watcher',
|
|
||||||
writeBundle() {
|
|
||||||
electronProcess && electronProcess.kill()
|
|
||||||
electronProcess = spawn(electron, ['.'], { stdio: 'inherit', env })
|
|
||||||
},
|
|
||||||
}],
|
|
||||||
build: {
|
build: {
|
||||||
watch: true,
|
watch: true,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue