-
-
Save qustosh/5294454 to your computer and use it in GitHub Desktop.
RequireJS example code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(["util/baz"], function(Baz) { | |
return { baz: new Baz() }; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define({ | |
"hello": "world" | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(function() { | |
var Foo = function(config) { | |
this.config = config; | |
}; | |
return Foo; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<DOCTYPE html> | |
<html> | |
<head> | |
<title>I am a layout</title> | |
</head> | |
<body> | |
<p>Hello World</p> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.plugin(function() { | |
//initialize a jQuery plugin. This isn't AMD code! | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(function() { | |
return function() { | |
}; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment