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.
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 ;)