0

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 so that it 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 an 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 override 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.

0

I thought that would have worked, have you run php bin/magento setup:static-content:deploy or however you are currently managing symlinks? Also clear browser cache and delete pub/static/frontend. See this answer for more info.

 If that still doesn't work:

If that still doesn't work you can use the Require JS config to do this.

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.

I've done it that way based off the dev docs example, I hope you will be able to do this and keep the JS file in the same file structure but I'm not sure how.

Using "MyExtension_MyExtensionSubfolder/js/script": "js/myExtensionCustom/script" may work but I can't test it at the moment.

Related dev docs page - http://devdocs.magento.com/guides/v2.0/javascript-dev-guide/javascript/custom_js.html

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.