I started learning javascript/jQuery and wanted to use RequireJS. The following is my file hierarchy:
my_project/
├── index.php
└── scripts/
├── require.js
├── loader.js
├── app/
│ ├── app.js // this is where I'd like to write functions for the app
│ └── helper/ // this folder is empty for now
└── lib/
├── jquery/
│ └── 1.10.2/
│ └── jquery.min.js
└── jqueryui/
└── 1.10.3/
└── jquery-ui.min.js
I read through RequireJS docs and StackOverflow posts (example) related to this and set up RequireJS configs to be something like this-
In my_project/index.php
, I have
<script data-main="scripts/loader.js" src="scripts/require.js"></script>
In scripts/loader.js
, I have
requirejs.config({
baseUrl: 'scripts/lib',
enforceDefine: true,
paths: {
"app": '../app', // mapping for my 'scripts/app/' directory
"jquery": [
'jquery/1.10.2/jquery.min',
//'//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min', this works
],
"jquery-ui": [
'jqueryui/1.10.3/jquery-ui.min',
//'//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min', this works
],
},
shim: {
"jquery-ui": {
exports: "$",
deps: ["jquery"],
},
},
});
In scripts/app/app.js
, I have
define(['jquery-ui'], function () {
.... // some js code here
}
Whenever I test the index.php
, I see (in Firebug console) Error: No define call for loader
, Error: No define call for jquery
and Error: Load timeout for modules: jquery-ui
. I can eliminate the last two errors by subbing local jQuery and jQueryUI libraries with CDN based one like Google's (shown above as comments).
I would like to know how to load jquery and jqueryUI from local files without getting Error: No define call for jquery
and Error: Load timeout for modules: jquery-ui
.
I'm sorry if this a long post. As I mentioned above, I am still learning javascript and am trying my best to keep my code clean. If any experienced coder could help me answer any of the above questions, I would really appreciate the help. Thank you.