Hot Module Replacement (HMR) is a web development technique that allows code changes to be applied instantly in a running application without requiring a full page reload. This significantly improves development productivity since the application's state (e.g., user input or UI state) is preserved.
HMR is used in modern build tools like Webpack, Vite, Parcel, or esbuild. The process works as follows:
✅ Faster development cycles – No need for full-page reloads.
✅ Preserved application state – Useful for React, Vue, and other SPA frameworks.
✅ Instant CSS updates – Style changes appear immediately.
✅ Improved DX (Developer Experience) – Reduces workflow interruptions.
If you're using Webpack, you can enable HMR like this:
if (module.hot) {
module.hot.accept('./module.js', function() {
console.log('Module updated!');
});
}
This ensures that changes to module.js
are applied without restarting the entire application.