How to inject custom values for HMR variables for Vite app

109 Views Asked by At

For example I want to redefine __HMR_PORT__ value.

enter image description here

How to do it exactly? I tried several approaches with .env files in root folder of app, but this variable is null each time in DevTools.

1

There are 1 best solutions below

0
On

I've found solution by my own, it's quite simple. In vite.config.js:

export default defineConfig({
  server: {
    hmr: {
      clientPort: 800,
    }
  },
  plugins: [svelte()],
})