My JS code is Backbone.js
based, so I think it is a good idea to separate "classes" with this logic as shown on picture (though I'm not sure where to place templates - in this packages or in global templates
folder, and do not mind main.js
- it is not related to CommonJS
packages) :
Now since there is fairly lot of them - I've decided to use require.js
to deal with this bunch of <script src=...
tags but got stuck with app.js
config file (which is the only one that I include like this -
<script data-main="/static/js/app.js" src="/static/js/libmin/require.js"></script>
What do I mean with stuck - of course I can iterate all this js files in require
statement using names like PlayerApp/PlayerAppController.js
, or using paths directive (not sure if it will make the code look not that ugly), but it would be cool if I can use something like python's from package import *
, and of course there is no such thing in require.js
.
The most similar thing is packages directive, but seems like it allows you to import only main.js
from each package, so then the question is - what is the most correct way to load other files of concrete package from CommonJS
's main.js
? I have even found a way to determine current .js file's name and path - like this, and given that I can make up other files names in current package(if I will keep naming them with the same pattern), but still do not know how to import them from main.js
Edit:
There might be an opinion that it is not very clear what exactly am I asking, so let me get this straight: how on Earth do I import a huge amount of javascript files with that project structure in the most nice way?