Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Dean's avatar
Level 7

Laravel Mix - generating JS with PHP

Is there a way to generate JS via a PHP script when running Mix?

Main reason I want to do it is to generate environment specific js file with things like algolia keys but there are a few other things I could see it being useful for.

0 likes
1 reply
bobbybouwmann's avatar

Right now there is no way to do that.

I would advise against this approach. I would create a config.js file that would not be in version control and set that up for each environment. Just like a .env file. You can even create config.js.dist file if you wish ;)

Please or to participate in this conversation.