I'm having trouble understanding how to set the base URL for requirejs given the structure of my project.
The issue: Not all html files will be on the same folder level. The script file paths keep changing depending on the location of the html page.
What I've tried: I've scoured the API, but I just don't understand what the BaseURL should be to get the correct path for all pages. I've tested variations (../js/lib, /js/lib/, I tried not including it all in the main.js file) but this one below is the only one that seems to produce the correct result on certain files.
Main.js
requirejs.config({
baseUrl: '../js/lib',
paths: {
'jquery' : (document.addEventListener) ? ['vendor/jquery'] : ['vendor/jquery-1.9.1']
},
shim: {
'foundation/foundation': {
deps: ['jquery']
},
'foundation/foundation.alert': {
deps: ['jquery', 'foundation/foundation']
},
'vendor/slick.min': {
deps: [
'jquery',
'foundation',
'foundation/foundation.interchange'
],
exports: 'slick'
}
}
});
requirejs(['jquery'
, 'foundation/foundation'
]);
Folder Structure
Main Folder
│
│ Some Folder
│ ├── css
│ ├── js
│ │ ├── lib
│ │ │ ├── foundation
│ │ │ │ ├── foundation.alert.js
│ │ │ │ ├── ...(foundation component js files)
│ │ │ │ ├── foundation.js
│ │ │ ├── vendor
│ │ │ │ ├── jquery-1.9.1.js
│ │ │ │ ├── jquery.js
│ │ │ ├── foundation.min.js
│ │ │ ├── slick.min.js
│ │ │ └── slickModule.js
│ │ ├── main.js
│ │ └── require.js
│ ├── html
│ │ ├── components
│ │ │ ├── slider.html [All scripts throw 404: Main Folder/Some Folder/html/js/lib/vendor/file.js ]
│ │ ├── home.html [loads files as expected]
│ │ ├── second.html [loads files as expected]
│ │ ├── subfolder
│ │ │ └── random.html
│ ├── extra folder
│ │ └── index.html [All scripts throw 404: Main Folder/Some Folder/extra folder/js/lib/vendor/file.js ]
│ │
│ Another Folder
│ ├── index.html [All scripts throw 404]
/html/components/slider.html
When I try to call require this way, the slickModule's url is "Main Folder/Some Folder/html/js/lib/slickModule.js" - note 'html' is added after the base url
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script data-main="../../js/main" src="../../js/require.js"></script>
<script>
require(['../js/main'], function () {
require(['slickModule']);
});
</script>
</head>
<body>
...
</body>
</html>
Could someone help me to see why this could be happening?
If it's even possible, what can I do to get the base URL to be consistent?