Attempt at fixing amd file's markdown on site.

This commit is contained in:
Levi Bostian 2014-10-18 13:19:07 -05:00
parent a3b9367e07
commit b9466505f5

View File

@ -136,6 +136,7 @@ require(['jquery', 'coolLibFromBower', 'modules/someHelpers'], function($, coolL
});
```
`require.js`-based apps will usually have a single entry point (`main.js`) that is passed to the `require.js` script tag as a data-attribute. It will be automatically loaded and executed on pageload:
```html
<!DOCTYPE html>
<html>
@ -155,13 +156,15 @@ Many people prefer using AMD for sane code organization during development, but
`require.js` comes with a script called `r.js` (that you will probably run in node.js, although Rhino is supported too) that can analyse your project's dependency graph, and build a single file containing all your modules (properly named), minified and ready for consumption.
Install it using `npm`:
```sh
```shell
$ npm install requirejs -g
```
Now you can feed it with a configuration file:
```sh
```shell
$ r.js -o app.build.js
```
For our above example the configuration might look like:
```javascript
/* file : app.build.js */
@ -177,10 +180,12 @@ For our above example the configuration might look like:
}
})
```
To use the built file in production, simply swap `data-main`:
```html
<script src="require.js" data-main="app/main-built"></script>
```
An incredibly detailed [overview of build options](https://github.com/jrburke/r.js/blob/master/build/example.build.js) is available in the GitHub repo.
### Topics not covered in this tutorial