How to get ENV type Laravel + VueJS + Homestead

I am developing an application using Laravel + VueJS + Homestead, and as is known on Laravel 5.2, we have an env file where we can set env variables ... I would like to do something similar, but so that I can get access this from my javascript code!

I read about proccess.NODE_ENV, but I don’t know if I understood it correctly, but it seems to work only on npm start no? When I launch my application through the estate, I really don't know how to do it!

Thanks in advance!

+4
source share
2 answers

APP_ENV , JavaScript, Vue.

<script type="text/javascript">
    var env = "{{ env }}";
</script>

...

$env = getenv("APP_ENV");

APP_ENV

+4

config.js, , :

const IS_LOCAL = process.env.NODE_ENV !== 'production'

const API_BASE_URL = IS_LOCAL
    ? 'http://api.domain.dev/v1'
    : 'http://api.domain.com/v1'

const LOGIN_URL = "auth/login"
const LOGOUT_URL = "auth/logout"
const REFRESH_URL = "auth/refresh"

export default {
    IS_LOCAL,
    API_BASE_URL,
    LOGIN_URL,
    LOGOUT_URL,
    REFRESH_URL
}

, , :

import {REFRESH_URL, LOGIN_URL} from "./config.js"
+8

All Articles