diff --git a/npm-packages/meteor-vite/src/meteor/IPC/methods/index.ts b/npm-packages/meteor-vite/src/meteor/IPC/methods/index.ts index 08f81139..5e31b3e2 100644 --- a/npm-packages/meteor-vite/src/meteor/IPC/methods/index.ts +++ b/npm-packages/meteor-vite/src/meteor/IPC/methods/index.ts @@ -23,6 +23,7 @@ export interface WorkerReplies { viteConfig: ViteRuntimeConfig refreshNeeded: void, workerConfig: WorkerRuntimeConfig & { listening: boolean } + startSSRWatcher: { serverEntry: string } } export type WorkerResponse = { diff --git a/npm-packages/meteor-vite/src/meteor/IPC/methods/vite-server.ts b/npm-packages/meteor-vite/src/meteor/IPC/methods/vite-server.ts index a3d4458e..057b36e9 100644 --- a/npm-packages/meteor-vite/src/meteor/IPC/methods/vite-server.ts +++ b/npm-packages/meteor-vite/src/meteor/IPC/methods/vite-server.ts @@ -33,6 +33,10 @@ export default defineIpcMethods({ await sendViteConfig(); }, + async 'vite.watch.ssr'({ packageJson }: DevServerOptions) { + await MeteorServerBuilder({ packageJson }); + }, + async 'vite.server.start'({ packageJson, meteorParentPid, meteorConfig }: DevServerOptions) { const ddpClient = DDPConnection.init(meteorConfig); const backgroundWorker = await BackgroundWorker.init(meteorParentPid, ddpClient); @@ -94,7 +98,15 @@ async function createViteServer({ ?? packageJson?.meteor?.viteConfig, }, 'serve'); + if (viteConfig.meteor?.serverEntry) { + await IPC.reply({ + kind: 'startSSRWatcher', + data: { serverEntry: viteConfig.meteor.serverEntry } + }) + } + viteDevServer = await createServer({ + mode: 'development', configFile: viteConfig.configFile, plugins: [ meteorWorker({ @@ -126,10 +138,6 @@ async function createViteServer({ ], }); - if (viteConfig.meteor?.serverEntry) { - await MeteorServerBuilder({ packageJson }); - } - process.on('warning', (warning) => { if (warning.name !== RefreshNeeded.name) { return;