-
-
Save markshust/b5a66517a8f4f9d40681945ce2f61672 to your computer and use it in GitHub Desktop.
What is RequireJS?
This file contains hidden or 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>Hi there!</title> | |
| <!-- Load the RequireJS library before all other scripts to be called --> | |
| <script src="js/require.js"></script> | |
| </head> | |
| <body> | |
| <h1>Hi there!</h1> | |
| <script> | |
| /* | |
| * The require.config() function accepts an object | |
| * | |
| * baseUrl defines which folder to reference for JavaScript files | |
| */ | |
| require.config({ | |
| baseUrl: "js" | |
| }); | |
| /* | |
| * RequireJS expects an array of dependencies as its first argument | |
| * | |
| * Dependencies are defined as strings without the ".js" extension | |
| * | |
| * The second argument is a function callback that accepts any number of | |
| * arguments which are mapped back to the defined dependencies. In this | |
| * case, 'jquery' maps to the $ variable. | |
| */ | |
| requirejs(['jquery'], function($) { | |
| // Dependencies are now accessible within the function callback. | |
| $(function() { | |
| console.log('Hi there!') | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment