Here is a sample application demonstrating the issue (sorry no fiddle since it's about r.js which is node based)
I can't get the requirejs optimizer to work properly with relative paths.
my web app has the following directories
require(['plugins'])
(standard multipage setup)../app-plugins/a.js
everything works fine in the non-optimized version (run a webserver at app, open console and navigate to the index page).
Optimizing, however, gives me an error because of the ../
in plugins.js. To see this cd to the optimization directory and run node .\node_modules\requirejs\bin\r.js -o .\build.json
. The error will be
W:\temp\requireop\optimization [master]> .\Build-RequireJs.ps1
Tracing dependencies for: main
Tracing dependencies for: plugins
Error: ENOENT, no such file or directory 'W:\temp\requireop\build\app-plugins\a.js'
In module tree:
plugins
Error: Error: ENOENT, no such file or directory 'W:\temp\requireop\build\app-plugins\a.js'
In module tree:
plugins
at Object.fs.openSync (fs.js:427:18)
I did the following changes and it worked:
main.js
:
baseUrl: 'scripts'
In the general case paths are case sensitive; also better not to include the leading slash.
optimization/build.json
becomes:
{
appDir: '../app',
baseUrl: 'scripts',
dir: '../build',
modules: [ // the same
]
}
You can find the details here, but some explanations:
appDir
lets r.js know where the sources are. I believe this also makes r.js know how to handle relative paths - not quite sure though.baseUrl
becomes relative to the appDir
.dir
is where the output goes, it will also copy files found in your appDir
in there.This process overwrites files in /build/
.