How to use Environment Variables in Vite(React Template Example)
tl:dr — Use import.meta.env instead of process.env
Vite is a handy build tool when you want to spin up a quick react application. In this guide, I will walk you through how to use environment variables inside a react application template created tho...
blog.ramadevsign.com2 min read
Ashutosh Jha
How can I add Environment Variables in Vite React Project in the vite.config.js file
import { defineConfig } from "vite"; import react from "@vitejs/plugin-react";
const proxy_url = "localhost/";
export default defineConfig({ plugins: [react()], server: { proxy: { "/api": { target: proxy_url, changeOrigin: true, rewrite: (path) => path.replace(/^/api/, ""), }, }, }, });