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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners