Michael
Michael

Reputation: 493

Globally enable HMR for Pinia without adding 'if (import.meta.hot)' in every store

I’m using Pinia in a Vue 3 + Quasar project, and I want to enable Hot Module Replacement globally, so I don’t have to add if (import.meta.hot) in every store file. Is it possible to do so, maybe somewhere in the src/stores/index.ts?

Right now, I have something like this in each store:

import { defineStore, acceptHMRUpdate } from 'pinia';

export const useStoreProducts = defineStore('products', {
  state: () => ({
    products: [],
  }),
  actions: {
    async loadProducts() {
      console.log('Loading products...');
    },
  },
});

if (import.meta.hot) {
  import.meta.hot.accept(acceptHMRUpdate(useStoreProducts, import.meta.hot));
}

I'm looking for a possible solution.

Upvotes: 0

Views: 20

Answers (0)

Related Questions