Load Laravel ENV Variables Into Javascript Files With Vite

Ariel Mejia

December 11th, 2022 - 1 min read

Let's imagine that our .env file has this value

VITE_API_PUBLIC_KEY=123

Then in your Javascript component or any frontend file you can get the value as

console.log(import.meta.env.VITE_API_PUBLIC_KEY)

Thanks for reading!


Ariel Mejia Illustration

Ariel Mejia

Laravel Senior Developer

Engineer with 7+ years of experience working in backend & frontend technologies
Open Source Maintainer of packages for Laravel community.

Stay up with Laravel

Sign up & get tips and tricks

You'll get monthly updates regarding my most recent articles and products.