1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-08-06 14:56:54 +02:00

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: `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 ```html
<!DOCTYPE html> <!DOCTYPE html>
<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. `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`: Install it using `npm`:
```sh ```shell
$ npm install requirejs -g $ npm install requirejs -g
``` ```
Now you can feed it with a configuration file: Now you can feed it with a configuration file:
```sh ```shell
$ r.js -o app.build.js $ r.js -o app.build.js
``` ```
For our above example the configuration might look like: For our above example the configuration might look like:
```javascript ```javascript
/* file : app.build.js */ /* 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`: To use the built file in production, simply swap `data-main`:
```html ```html
<script src="require.js" data-main="app/main-built"></script> <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. 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 ### Topics not covered in this tutorial