Magento RequireJS & JavaScript Components
Create RequireJS Aliases with map and paths
Free Preview
app/code/Macademy/JsFun/view/frontend/requirejs-config.js
/*
The "*" in the "map" prop makes the alias available to all JavaScript components.
The format for aliases is: "alias": "<Vendor_Module>/js/filename"

The area can either be "base", "frontend", or "adminhtml".

<Vendor_Module>/js/filename
maps to ->
<Vendor>/<Module>/view/<area>/web/js/filename.js

Paths can be used for non-AMD JavaScript modules & external files, just be sure
to not include the ".js" extension as this is automatically appended.
*/
var config = {
    "map": {
        "*": {
            "fadeInElement": "Macademy_JsFun/js/fade-in-element"
        }
    },
    "paths": {
        "vue": "https://cdn.jsdelivr.net/npm/vue/dist/vue"
    }
};
app/code/Macademy/JsFun/view/frontend/templates/block-promo-effects.phtml
<script>
// After defining an alias, it can then be used when requiring dependencies.
require(['jquery', 'fadeInElement'], function($, fadeInElement) {
    'use strict';

    $(function() {
        fadeInElement('.block-promo');
    });
});
</script>
Want to learn more?

Visit M.academy to learn much more about Magento, Laravel, PHP, Javascript, & Docker.

M.academy logo