Best way to generate and serve javascript files (no html) with Laravel?
I have read the docs front to back, and read every google article I could find, but I cannot find the information I need....
Context:
My server is going to be serving javascript bundles to <script> tags in client websites. When the server receives a request from one of these <script> tags it needs to dynamically generate the javascript bundle (using information from Laravel models) before serving it (I will be using caching, so probably most of the time it will just find a cached version instead of having to generate fresh code each time).
Here are the ways I have found that you can do this with Laravel, along with the problems I see with each approach. If there is another way, that doesn't have these problems, please let me know!
Known approaches (all flawed):
Serve static js files from 'public' directory (aka. 'assets') and fill in the dynamic parts of the code by making requests back to the server from the client side. DRAWBACK: this will require many HTTP requests (ie. will be too expensive and slow), and seems silly since the information necessary is already present on the server from the start. And the Auth gets much more complicated.
Keep everything in a Laravel PHP class (probably in a Controller), and generate the js files as strings using PHP. DRAWBACK: Working with js-formatted strings means I lose all IDE features that make writing JS reasonably fast. As the js I'm serving will be at least several hundred lines long, trying to write that as laravel strings seems like a real pain.
When my server gets a request from a script tag it is going to get a specific 'configuration' object based on the meta info of that request. This 'configuration' will specify, at least, a series of DOM manipulations and also React components+props which the js bundle sent back to the client needs to include. This configuration object is based on the business logic that I write in my Laravel models, etc.
The ideal solution would be if I could use Blade templates, and all the helpful features they include. However as far as I can tell blade templates can't generate plain javascript, it has to be wrappen in HTML.