Fast Refresh & HMR

Hot Module Replacement (HMR) is the ability to push file updates to the browser without triggering a full page refresh. Imagine changing some CSS, hitting save, and then instantly seeing your change reflected on the page without a refresh. That’s HMR.

Snowpack supports full HMR out-of-the-box for the following served files:

  • CSS
  • CSS Modules
  • JSON

Popular frameworks can also be set up for HMR. Create Snowpack App (CSA) ships with HMR enabled by default for all of the following frameworks. If you’re not using CSA, you can setup HMR in your application with a simple plugin or a few lines of code:

For more advanced HMR integrations, Snowpack created the esm-hmr spec, a standard HMR API for any ESM-based dev environment:

// HMR Code Snippet Example
if (import.meta.hot) {
import.meta.hot.accept(({ module }) => {
// Accept the module, apply it into your application.
});
}

Check out the full ESM-HMR API reference on GitHub.