4.7 (94.1%) 78 votes

In this topic we will show you How to Override Magento JS Core in Magento 2 through 2 steps:

Hello everyone. Sometimes, you want to change the Magento JS core. But you can not change directly in Magento source code. So you must override the Magento JS. In this blog, I will show you how to override the Magento JS core and replace it by your custom Javascript.

Step 1:

  • Create a RequireJS configuration file requirejs-config.js

  • Where the following notation is used:

<default_component>: the name of the default component you replace

<custom_component>: the name of the custom component

  • Example, if you want to use custom navigation-menu.js script instead of the default menu widgets, your requirejs-config.js should contain the following:

Step 2:

Place your requirejs-config.js file in one of the following directories (it depends on the location of your custom script):

  • Your theme files: <theme_dir>
  • Your module view files: <module_dir>/view/frontend</code>

The 2 steps I mention above is the shortest process for you to Override Magento JS Core in Magento 2. With this guide, you can manage the Magento JS Core in Magento 2 easily. Every store has a Magento JS Core in Magento 2 with many attributes.

Thank you for reading this post and see you in other posts from Magestore!

How to Get all Translation Labels from PHP and JS files of Magento 2 Extension
How to Configure Color Swatches in Magento 2 - Magento 2.3