Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chrisgrim's avatar

Setting up global routing for image paths in Vue 2

In my Vue/Laravel project I am currently using relative routes. However, I am currently in the process of switching to DO spaces for my image hosting. I am going to go through my whole project and switch to absolute routes for all of my images. However, before I do all that work it would be great if the image url could be a variable I could change in one location (for local and production), similar to how laravel uses the .env file.

Would this be something I could add globally easily without having to pass it into components? Thanks!

0 likes
10 replies
Sinnbeck's avatar

You could use your env file? Are you using vite or mix?

chrisgrim's avatar

Ok Ill give this a shot and report back!

chrisgrim's avatar

@Sinnbeck This worked perfect. Such a simple way for me to adjust my Vue code based on my .env file

Sinnbeck's avatar

@chrisgrim yeah it's really nice. Just make sure you don't expose your passwords or such :)

chrisgrim's avatar

@sinnbeck I had an issue pop up using Mix Environment variables. When I run laravel mix dev I need it to read my dev file location from the .env

MIX_IMAGE_URL=https://DEV.sfo3.digitaloceanspaces.com/public/

and when I run production I need it to read a different URL

MIX_IMAGE_URL=https://PROD.sfo3.digitaloceanspaces.com/public/

However there is no way I can see to do an if/then statement in a .env file. Have you had to deal with this ever?

Please or to participate in this conversation.