I'm building a Laravel 5.2 app which contains a fair bit of client-side JS: third-party libraries such as Angular and jQuery, plus several of my own Angular modules. For example, I have one module that powers the advanced search form, one for the comment widget, one for shared UI components, etc.
To avoid bloating my pages, I want to load these modules only on the pages that need them – and I also want to keep shared dependencies (such as the UI components) in their own bundles. I'm using gulp and Browserify to create these bundles.
Browserify takes care of each module's internal dependencies. But how can I sanely manage the dependencies between the bundles? That is, how can I put something like this in my template:
@enqueuejs('js/advanced-search.js')
@enqueuejs('js/comment-widget.js')
...and have my app automatically figure out the dependencies for those modules, dedupe any common dependencies, sort them into the right order, and render the <script> tags into the page?
Basically, I'm looking for an equivalent to Wordpress' wp_enqueue_script(). It looks like Laravel 3 had an Asset class which did exactly this – but it was removed in (I think?) Laravel 4.
In theory, I could using something like RequireJS to figure out the dependencies client-side. But, implementing that on top of Browserify sounds like a nightmare. Besides, a client-side dependency manager would just be one more piece of JS that the browser has to download and process. A simple list of <script> tags is low-tech and effective.
Apologies if I'm being daft here – I don't have much experience with JavaScript dependency management.
Any guidance you can offer would be appreciated – I've been struggling with this for longer than I care to admit. Thanks!
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/20E9QoJ
via IFTTT
Aucun commentaire:
Enregistrer un commentaire