This guide explains how to configure a Vite project to change the port and enable network URL or set the host to true simultaneously.
By default, Vite runs on port 3000 and only listens on localhost. You can change the port and enable network URL by setting the host to true in the Vite configuration.
- Open your Vite project's
vite.config.jsfile (or create one if it doesn't exist). - Add the
portandhostoptions in theserverconfiguration.
import { defineConfig } from 'vite';
export default defineConfig({
server: {
port: 5000, // Change the port to your desired value
host: true, // Enable network URL by setting host to true
},
});Replace 5000 with the port number you want to use. This configuration will make your Vite server accessible over the network using your machine's IP address or network URL.
Feel free to customize these configurations based on your project's requirements.