How to use require.js in your project. You can find the documentation.
Step 1
load your script after requirejs loads. “data-main” is the entry point of your script.js.
Step 2
Set up the library path (baseUrl). This is where you store your dependencies, like jQuery.
Step 3
To create a module using define(). The first parameter is the module name. Second parameter is the dependency array. Thrid parameter is the callback function.
Let’s say this module doesn’t have any dependencies, so we leave the 2nd parameter empty.
Step 4
Create another module but this module is calling the jquery dependency.
Step 5
Create a module that have dependencies of module1 and module2.
Previously, we created two modules (module1 and module2). Each of these dependencies have its own methods. Now, in this module, we’re going to utilize these methods.
Step 6
Create an app module to use the simplified wrapper design pattern.
Step 7
Module dependencies diagram
These design patterns are pretty similar to JavaScript Self-invoked function design patterns. Instead of using IIFE, it utlizes define() and require(). You can find these design patterns here.