简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM