cancel
Showing results for 
Search instead for 
Did you mean: 

How to override a java script file from an extension in your theme in Magento 2

SOLVED

How to override a java script file from an extension in your theme in Magento 2

So, I have a js file from an extension, that i need to override

 

the path is :  app/code/MyExtension/MyExtensionSubfolder/view/frontend/web/js/script.js

Where should i put the new js file, that will override script.js from above? And what else is necessary for this to work.

 

If I want to override a .phtml file from this extension, is simple. Create a new folder in

app/code/design/frontend/Venustheme/kasitoo  with the name combined MyExtension_MyExtensionSubfolder and then follow the path from extension and put here the phtml and it works.

 

But for js file from example if I create a new js file called script.js to the path

app/code/design/frontend/Venustheme/kasitoo/MyExtension_MyExtensionSubfolder/web/js/script.js is not working.

 

So the question is where should I put my new js file with the modifications I made, that will overide the script.js from the extension. Because if I made the changes directly in the extension, after the first update of the extension, I will lose those changes.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to override a java script file from an extension in your theme in Magento 2

Hi!

 

Actually the magento documentation is not explained clearly from my point of view. Someone else responded to me on another site and the solution worked. I will put it here, maybe it will help others:

 

Create or modify app/design/frontend/yourStore/yourTheme/requirejs-config.js

var config = {
  "map": {
    "*": {
      "oldScriptAliasOrPath": "newScriptAliasOrPath",
      "MyExtension_MyExtensionSubfolder/js/script": "js/myExtensionCustom/script",
    }
  }
};

First one is a generic example and the second one is using your file as an example. Using this method means your JS file would be placed in app/design/frontend/yourStore/yourTheme/web/js/myExtensionCustom/script.js.

View solution in original post

2 REPLIES 2

Re: How to override a java script file from an extension in your theme in Magento 2

Re: How to override a java script file from an extension in your theme in Magento 2

Hi!

 

Actually the magento documentation is not explained clearly from my point of view. Someone else responded to me on another site and the solution worked. I will put it here, maybe it will help others:

 

Create or modify app/design/frontend/yourStore/yourTheme/requirejs-config.js

var config = {
  "map": {
    "*": {
      "oldScriptAliasOrPath": "newScriptAliasOrPath",
      "MyExtension_MyExtensionSubfolder/js/script": "js/myExtensionCustom/script",
    }
  }
};

First one is a generic example and the second one is using your file as an example. Using this method means your JS file would be placed in app/design/frontend/yourStore/yourTheme/web/js/myExtensionCustom/script.js.