Whenever i run npm run dev
, i get vite running on domain 127.0.0.1 by default.
How to make vite run on localhost instead?
Theses are my configs:
package.json:
"scripts": {
"dev": "vite --host=localhost",
"build": "vite build",
"preview": "vite preview"
},
vite.config.js:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
host: 'localhost',
port: 3000
}
})
This is intended. You can consult vite localhost behavior (read the note).
To disable this behavior set dns.setDefaultResultOrder('verbatim')
as explained there or upgrade Node.js to 17+. Also localhost
in your vite.config :
import { defineConfig } from 'vite'
import dns from 'dns'
import react from '@vitejs/plugin-react-swc'
dns.setDefaultResultOrder('verbatim')
export default defineConfig({
plugins: [react()],
server: {
host: 'localhost',
port: 3000
}
})
Result:
Hope it answers to your question ! :)