Skip to content

Commit 1d24f54

Browse files
committed
Added an explanation of the setup to readme
1 parent bc46627 commit 1d24f54

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This example shows one way to load jQuery and jQuery plugins with require.js. j
55

66
The most important part is the app.js file, which specifies the [shim configuration](http://requirejs.org/docs/api.html#config-shim) for the plugins.
77

8-
###File structure
8+
###Project structure
99

1010
- tools/
1111
- build.js
@@ -23,6 +23,41 @@ The most important part is the app.js file, which specifies the [shim configurat
2323
- app/
2424
- main.js
2525

26+
###How it's set up
27+
The main file of this setup is www/js/app.js. It is loaded from app.html by this line:
28+
```html
29+
<script data-main="js/app" src="js/lib/require.js"></script>
30+
```
31+
32+
App.js is mainly about configuration. The shim configuration specifies jQuery as a dependency for jQuery.alpha and jQUery.beta. Finally, our main code is loaded at the bottom of the file:
33+
34+
```javascript
35+
requirejs.config({
36+
"baseUrl": "js/lib",
37+
"paths": {
38+
"app": "../app"
39+
},
40+
"shim": {
41+
"jquery.alpha": ["jquery"],
42+
"jquery.beta": ["jquery"]
43+
}
44+
});
45+
46+
// Load the main app module to start the app
47+
requirejs(["app/main"]);
48+
```
49+
50+
App/main.js is where the app logic is:
51+
52+
```javascript
53+
define(["jquery", "jquery.alpha", "jquery.beta"], function($) {
54+
//the jquery.alpha.js and jquery.beta.js plugins have been loaded.
55+
$(function() {
56+
$('body').alpha().beta();
57+
});
58+
});
59+
```
60+
2661
###How to see it in action
2762

2863
Just serve up the www/ folder using any web server you'd like. If you have python installed, an easy way is to navigate into the www/ directory and type `python -m SimpleHTTPServer`

0 commit comments

Comments
 (0)