Given a project with the files below and a directory structure as follows:
$ tree --charset ascii
.
|-- index.html
|-- js
| |-- components
| | `-- vendor
| | |-- jquery-1.7.2.js
| | |-- jquery.js
| | `-- test.js
| |-- order.js
| `-- require.js
`-- nested
`-- path
`-- index.html -> ../../index.html
5 directories, 7 files
Note that the file names are below, but the directory structure is not preserved
since github gist's don't allow subduers. The directory is served statically
(using something like python -m SimpleHTTPServer
), with the require.js
config
set with baseUrl: '/js'
and the following URLs are visited:
http://127.0.0.1:8000/
http://127.0.0.1:8000/nested/path/
Here the page load works, but there are two gotchas:
@aaronj1335: yes sounds like you have it worked out now. Typically the entry point JS file is effectively "global" in that it is in the baseUrl, so relative paths are not needed for it, and using require() in there is fine instead of define. If you use data-main="" then the entry point script can use define().
@justinbmeyer: I should have kept going in that example, there is no double mapping. It will want to load it from baseUrl/b.js, since it resolved the relative ID relative to another ID, not a path. This is done because it would not make sense to encode path names in a built file -- those are also meant to be combined with other modules, and they expect to find modules at ID values, not path values.
Your example is correct: saying require(['jquery']) will load from baseUrl/jquery.js (unless of course there is a paths config that says otherwise). So, a global require can use './jquery' relative path, it is just relative to baseUrl.