Q:

Laravel mix with PHP helpers

In my homepage I have defined a section to forward variables to JS side in a way that I call PHP helper methods, for example:
<script>
    var base_url = "{{ url('/') }}";
</script>

This works within blade template, however if I put that to a script and try to minify through Laravel mix, it just gets compressed as a string literal. How could I force resolving this before somehow? Or keep it working within a minified file?

A:

According to Laravel Docs we may inject environment variables into Mix by prefixing a key in your .env file with MIX_ After the variable has been defined in your .env file, you may access via the process.env object. if you using Vue you can use This Package A Simple plugin for loading an environment file.

