@django-vite/vite-server
Version:
This provide cli to start Express Server with Chokidar to detect any file changes and send events.
66 lines (57 loc) • 1.8 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<title>Vite Hot Reloading</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
height: 100vh;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
font-family: system-ui, sans-serif;
}
h1 {
font-weight: 900;
text-align: center;
}
p {
text-align: center;
max-width: 400px;
}
</style>
</head>
<body>
<h1>Hot Reloading with Vite and Django</h1>
<p>
This is a part of Django-Vite-HMR middleware but this can be used
for any web applications.
</p>
<script>
const socket = new WebSocket("ws://localhost:5173/");
socket.onmessage = (event) => {
console.log(event);
if (event.data === "reload") {
window.location.reload();
};
};
socket.onerror = (error) => {
console.error("WebSocket error:", error);
};
// Event handler for when the WebSocket connection is closed
socket.onclose = () => {
console.log("WebSocket connection closed");
};
</script>
</body>
</html>