How to add custom JavaScript and mixins in Magento 2 with requireJS?

How to add custom JavaScript and mixins in Magento 2 with RequireJS – Today we will see how to add custom javascript file and a mixin file to same RequireJS file in custom module. I recently faced a practical issue to add a javascript and a mixin file to RequireJs file to one of my custom checkout module.

We can simply add an external file to RequireJs file like below.

And also we can add a mixin file like below.

Here is the sample module directory structure which contains custom javascript file and mixin file.

how to add require js in magento 2
Sample Module structure.


But i want to add both JavaScript file and mixin to one RequiJs file. So we can add both in requirejs-config.js file like below.

Like this we can add javascript file and mixin file in requirejs-config.js file. Hope this will help you in your magento custom development.

You can read more interesting articles on create graphql module in magento 2.

Read and share your thought + share this article too 🙂 .

Leave a Reply

Your email address will not be published. Required fields are marked *