Add your JS file inside of the theme directory like: <theme_dir>/web/js/Your_custome.js
Create the “requirejs-config.js” in your root directory of theme like: <theme_dir>/requirejs-config.js
Add the following code in “requirejs-config.js” file.
Here the function “map” is to map your file with the alias name of your custom JS file provided.
In the above example, “Any_name_for_JS” is basically the alias of the custom JS file “Your_custome.js”. While, the functionality of the “shim” is to add a dependency of other JS library files.
Here, “Your_custome.js” file relies on the main jQuery library, hence you need to add the following line for the shim function.
If you have various other dependencies of jQuery files or libraries, you can add them by “comma” in the code.
WRITTEN BY: Jeegnasa Mudsa
Jeegnasa Mudsa is Executive Director at CMARIX Technolabs Pvt. Ltd. a leading eCommerce development company with 15+ years experience. A blend of true Engineer and…
FEW MORE POSTS BY Jeegnasa Mudsa: