template-vite-ts
template-vite-ts copied to clipboard
Is HMR supported?
In the current version, changes to any file cause a full page/game reload.
Is it possible to use Hot Module Replacement (HMR) facilities to cause only the subset of modified code to be reloaded with this template? Is it feasible to use HMR at all with Phaser?
In this template is not supported, but try to replace this code inside src/main.ts. However, keep in mind that the game will still reload.
import StartGame from './game/main';
let game: Phaser.Game;
function launchGame() {
game = StartGame('game-container');
}
if (import.meta.hot) {
import.meta.hot.accept('./game/main', (mod) => {
if (game) {
game.destroy(true);
}
game = mod.default('game-container');
});
import.meta.hot.dispose(() => {
if (game) {
game.destroy(true);
}
});
}
document.addEventListener('DOMContentLoaded', launchGame);