Skip to content

Instantly share code, notes, and snippets.

@SubhajitSK
Created March 21, 2024 17:24
Show Gist options
  • Save SubhajitSK/fb08c02874bac8e3845bcb59fd5236c7 to your computer and use it in GitHub Desktop.
Save SubhajitSK/fb08c02874bac8e3845bcb59fd5236c7 to your computer and use it in GitHub Desktop.
Configuring Vite Project for Network Access

Vite Configuration Guide

This guide explains how to configure a Vite project to change the port and enable network URL or set the host to true simultaneously.

Changing Port and Enabling Network URL (Setting Host to True)

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.

  1. Open your Vite project's vite.config.js file (or create one if it doesn't exist).
  2. Add the port and host options in the server configuration.
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment