In this tutorial we're going to learn how we can use our.env variables inside the webpack.js config. This is perfect for the example of when you have a different javascript file based of an variable. Maybe you have a cross region application where you have a uk.js file and a us.js file, you'll use the APP_REGION environment variable to decide which javascript file to compile. https://paulund.co.uk/how-to-use-env-variables-in-webpack-js#laravel-mixIf you're using Laravel mix then there's already a nice way you can include environment variables in your javascript.

But these variables are not available in your webpack.mix.js file, therefore you can't compile your assets based off environment variables.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners