'Use environment variables in Laravel Nova

I am trying to follow: https://laravel.com/docs/9.x/mix#environment-variables

My project setup is

  • Laravel Framework 8.4
  • Php 7.4
  • Laravel Nova 3.0

.vue file in /nova-components/Nova-Component-Name/resources/js/components/ComponentName

export default {
    name: "SomeName",
    components: {
        SomeComponent,
    },
    data: () => ({
        baseURL: process.env.MIX_APP_URL
    }),
}

.env file

MIX_APP_URL=<url>

webpack.mix.js file

const mix = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css');


Solution 1:[1]

In order to use env variable in vue app you need to declare them with prefix VUE_APP

EG:VUE_APP_MIX_APP_URL

For more information check this

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 A.Z