Source: https://github.com/omnisyle/vite-svelte-ts-tailwind
If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR.
// store.ts
import { writable } from 'svelte/store'
export default writable(0)