Skip to content

Instantly share code, notes, and snippets.

@jbuck
Created April 2, 2013 16:40
Show Gist options
  • Save jbuck/5293765 to your computer and use it in GitHub Desktop.
Save jbuck/5293765 to your computer and use it in GitHub Desktop.
RequireJS example code
define(["util/baz"], function(Baz) {
return { baz: new Baz() };
});
define({
"hello": "world"
});
define(function() {
var Foo = function(config) {
this.config = config;
};
return Foo;
});
<DOCTYPE html>
<html>
<head>
<title>I am a layout</title>
</head>
<body>
<p>Hello World</p>
</body>
</html>
var require = requirejs.config({
// Set the root path for modules
baseUrl: "/src"
// Create aliases for long URLs
paths: {
"text": "external/require/text",
"jquery": "external/jquery/jquery-1.9.1"
},
// Define dependencies for non-AMD code
shims: {
"plugins/sweet.jquery": "jquery"
}
})
require(["foo", "bar", "config", "text!layout.html", "plugins/sweet.jquery"], function(Foo, Bar, config, LAYOUT, sweet) {
var foo = new Foo(config);
})
jQuery.plugin(function() {
//initialize a jQuery plugin. This isn't AMD code!
});
define(function() {
return function() {
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment