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:
Yes, define() is required for resolution relative to the module needing it. In the above case, the require() is the global require, not a local one that knows its relative position, but define() allows for that.
Also note that module IDs are resolved relative to other module IDs, not relative to paths. So for instance if you have this structure:
and do this kind of config:
and a.js looks like:
Then foo/c.js looks like:
Since the module ID for foo/c.js is 'c', then its require call is resolved as looking like 'c/./b', which is 'b', which then just gets mapped to baseUrl + 'b.js'.
This is not normally a problem though, only shows up when doing a paths map for a higher level ID to a lower lever/multiple directory argument.