The question is published on by Tutorial Guruji team.
I have a Vue component in my Laravel application.
I want to retrieve a URL that is in a config (or the .env Laravel file) directly in my Vue component, instead of hardcoding it. In webpack laravel mix I can retrieve my .env variable like this.
let proxyUrl = process.env.APP_URL
But when I want to do this in my app.js, I have a
can't resolve fs when trying to require dotenv.
What is the best way to have this data available in my Vue components ?
If this is the case you can inject environment variables into Mix, you just need to add the prefix MIX_. So you can add to your .env file a variable like:
you can access this anywhere in your pre compile file. You can find this information in the laravel documentation. https://laravel.com/docs/5.6/mix#environment-variables