Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

requireJS an entire folder

Is it possible to "require" an entire folder using requireJS.

For example, I have a behaviors folder with a ton of behavior js files. I'd really like to be able to simply use require(['behaviors/*'], function() {...}); to load everything in that folder rather than having to keep that list up to date. Once compressed and optimized I'd have all those files lump together, but for development it's easier to work with them individually.

like image 574
nicholas Avatar asked May 05 '11 05:05

nicholas


1 Answers

javascript in browser has no filesystem access and so it can't scan a directory for files. If you are building your app in a scripting language like php or ruby you could write a script that scans the directory and adds the file names to the require() call.

like image 75
greggreg Avatar answered Sep 28 '22 04:09

greggreg