5 years ago

Modular way to structure js files

Posted 5 years ago by kfirba


As we all know, laravel makes the back-end development extremely easy and modular. You can have as many classes as you want and as long as you follow psr-0 or psr-4 they will all be autoloaded.

However, when it comes to the front-end, I'm in a pinch. I tried to use RequireJS but after learning about it, I realized that the directory I work on, isn't for production. If I want to avoid tons of HTTP requests, I should use r.js to append my JavasScript files in the right order and make it work. However, it seems like I need to work on directory x and when I publish my website I should publish the x-build directory which r.js generates.

I couldn't figure out how it should be done with Laravel since we have only one public folder and I don't want to "hack" the framework.

Do you know any other way I can make my JavaScript workflow modular while maintaining the usage of 3rd library and dependencies (Loading order does matter)?

Please sign in or create an account to participate in this conversation.