Skip to content

Commit

Permalink
fix: #277 #community-256
Browse files Browse the repository at this point in the history
  • Loading branch information
RSamaium committed Jan 12, 2024
1 parent 53dce23 commit 924ec6d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 11 additions & 0 deletions packages/compiler/src/build/vite-plugin-config.toml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ export default function configTomlPlugin(options: ClientBuildConfigOptions = {},
else if (id.endsWith('virtual-server.ts')) {
const codeToTransform = dd`
import { expressServer } from '@rpgjs/server/express'
import { RpgWorld } from '@rpgjs/server'
import * as url from 'url'
import modules from './${MODULE_NAME}'
import globalConfig from './${GLOBAL_CONFIG_SERVER}'
Expand All @@ -524,6 +525,16 @@ export default function configTomlPlugin(options: ClientBuildConfigOptions = {},
globalConfig,
basePath: __dirname,
envs: ${envsString}
}).then(({ server, game }) => {
if (import.meta['hot']) {
import.meta['hot'].on("vite:beforeFullReload", () => {
server.close();
RpgWorld.getPlayers().forEach(player => {
player.gameReload();
});
game.stop();
});
}
})
`;
return codeToTransform
Expand Down
10 changes: 0 additions & 10 deletions packages/server/src/express/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,5 @@ export function expressServer(modules: ModuleType[], options: ExpressServerOptio
process.on('unhandledRejection', function (reason: any) {
console.log(pe.render(reason))
})

if (import.meta['hot']) {
import.meta['hot'].on("vite:beforeFullReload", () => {
server.close()
Query.getPlayers().forEach(player => {
player.gameReload()
})
rpgGame.stop()
});
}
})
}

0 comments on commit 924ec6d

Please sign in to comment.