A single entry point to your application is possible with RequireJS by using the data-main
attributed within the <script>
tag.
<script type="text/javascript" data-main="scripts/main" src="http://requirejs.org/docs/release/2.3.2/minified/require.js"></script>
On load, RequireJS will look for the data-main
attribute and inject the main script tag into the DOM with the async
attribute set. It is this file that you will want to do any configuration before kicking off your application.
For example:
// contents of scripts/main.js
require.config({
waitSeconds: 10,
paths: {
jquery: 'libs/jquery-1.4.2.min'
}
});
requirejs(["jquery", "libs/say"], function($, say) {
var $body = $('body');
$body.append( $('<p/>').text(say.hello("english")) );
$body.append( $('<p/>').text(say.hello("spanish")) );
$body.append( $('<p/>').text(say.hello("french")) );
});