How to give alias to the require js file with requirejs-config JS magento 2?

Magento requirejs-config file provides an alias for the custom js file declared inside map or path object.

You can use an alias anywhere inside a template or other Require JS file in the Magento system.

Create a requirejs-config.js file in your module, Continue reading “How to give alias to the require js file with requirejs-config JS magento 2?”

How to passing Dynamic arguments from template to RequireJs in magento 2?

Magento template support script tag with X-MAGENTO-INIT declaration. You can pass dynamic PHP values to Javascript from a template file.

create demo.phtml file in your module to pass dynamic PHP value to Javascript, Continue reading “How to passing Dynamic arguments from template to RequireJs in magento 2?”

How to load JAVASCRIPT In a PHTML template with requirejs VIA X-MAGENTO-INIT?

Magento 2 template supports require JS declaration using X-MAGENTO-INIT. You can define require js with the Magento PHTML template file.

Require js loaded as AMD (Asynchronous module definition) based approach.
Benefit:
Declare JS using text/x-magento-init will be loaded after the page DOM is loaded completely. It will improve the page load time. Continue reading “How to load JAVASCRIPT In a PHTML template with requirejs VIA X-MAGENTO-INIT?”