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:
This example does not explicitly set a baseUrl to the js directory (by either using data-main or calling requirejs.config()) so the baseUrl is set to the document root. You can change this by doing the following:
Or in main.js doing this before the require call:
requirejs.config({
baseUrl: '/js'
});
I thought the relative path thing on twitter was about doing a './id' dependency reference in a define()d module. Those are supported too, by doing: