I use requireJS to load scripts. It has this detail in the docs :
The path used for the module name must not contain the .js extension, since path mapping may be for the directory.
In my application, I map all my script files in the configuration path because they are dynamically generated at runtime (my scripts start life as things like order.js , but become like order.min.b25a571965d02d9c54871b7636ca1c5e.js (this is a hash of the file’s contents , for caching purposes).
In some cases, require will add a second .js extension at the end of these paths. Although I generate dynamic paths on the server side and then fill in the config path, I must then write additional javascript code to remove the .js extension from the problem files.
Reading requireJS docs, I really don't understand why you ever wanted route matching to be used for a directory. Does this mean that you can somehow download the whole directory at the merits of files in one call? I do not understand.
Does anyone know if it’s possible to just force me to stop adding .js to the file paths, so I don’t have to hack them?
thank.
UPDATE: some code samples were added as requested.
This is inside my HTML file (this is a Scala project, so we cannot directly write these variables to a .js file):
foo.js.modules = { order : '@Static("javascripts/order.min.js")', reqwest : 'http://5.foo.appspot.com/js/libs/reqwest', bean : 'http://4.foo.appspot.com/js/libs/bean.min', detect : 'order!http://4.foo.appspot.com/js/detect/detect.js', images : 'order!http://4.foo.appspot.com/js/detect/images.js', basicTemplate : '@Static("javascripts/libs/basicTemplate.min.js")', trailExpander : '@Static("javascripts/libs/trailExpander.min.js")', fetchDiscussion : '@Static("javascripts/libs/fetchDiscussion.min.js")' mostPopular : '@Static("javascripts/libs/mostPopular.min.js")' };
Then inside my main.js :
requirejs.config({ paths: foo.js.modules }); require([foo.js.modules.detect, foo.js.modules.images, "bean"], function(detect, images, bean) {
In the above example, I need to use the string "bean" (which refers to the require path), and not on my direct object (for example, others use foo.js.modules.bar ), otherwise I get the added extra .js .
Hope this makes sense.