Hot Module Replacement

The reading of this section is not required since it's just a feature to improve DX.

What is Hot Module Replacement?

Hot Module Replacement (or HMR) is a feature that allows you to update your application code without having to refresh the page. It is a very useful feature for development since it allows you to see the changes you make to your code in real time. It is also very useful for debugging since you can see the changes you make to your code without losing the state of your application.

HMR in Vulmix

Vulmix comes with HMR enabled by default. You can see it in action by running the dev command:

# With NPM
npm run dev

# Or with Yarn
yarn dev

As an example, let's create a new component called ComponentOne.vue in the components folder with the following content:

  <h1>I'm the ComponentOne!</h1>

Now, create another component called ComponentTwo.vue, this time with a counter, in the same folder with the following content:

    <h1>I'm the ComponentTwo!</h1>
      Counter: {{ counter }}
      <button @click="counter++">Increment</button>

<script setup>
  const counter = ref(0)

Now, let's use both components in the app.vue file:

    <ComponentOne />
    <ComponentTwo />

You should see the following result:

HMR Example

Now, let's increment the value and make some changes to the ComponentOne.vue. Notice how the counter value of the ComponentTwo.vue component is not reset and the changes to the ComponentOne.vue are reflected in real time:

HMR Example