Can we rewrite files in the lib folder?

If we can, I want to know how to rewrite /lib/web/magnifier/magnifier.js file in a custom module.

  • Have you tried rewrite the file in design folder? Do you only need to overwrite the file in your custom module? – aravind Feb 11 at 8:22
  • I need to overwrite in custom module so that my modifications will reflect in all the themes. – nagaratna Feb 11 at 11:01
  • Have you followed the steps posted in below answer by sandip? – aravind Feb 11 at 11:12

Try it below in the custom module. This is a working example.

  1. Create requirejs-config.js in app/code/Custom/Pro/view/frontend directory if not exists.

var config = { map: { '*': { "magnifier/magnifier": "Custom_Pro/js/magnifier/magnifier" } }, shim:{ "Custom_Pro/magnifier/magnifier":["jquery"] } };

  1. Create file named magnifier.js in app/code/Custom/Pro/view/frontend/web/js/magnifier directory. Copy original magnifier.js file from lib/web/magnifier/magnifier.js and paste it in app/code/Custom/Pro/view/frontend/web/js/magnifier directory.

  2. Make the required changes in the magnifier.js located in the app/code/Custom/Pro/view/frontend/web/js/magnifier/magnifier.js

  3. Execute below command in order to effect at frontend php bin/magento setup:upgrade php bin/magento s:s:d -f -s standard

Note: 1. Change your custom module from Custom/Pro. 2. To confirm check below file calling on the frontend. www.example.com/static/versionXXXXXX/frontend/Vendor/Theme/en_US/requirejs-config.js

For More Info. Refer Replace a default JS component section available at the below URL. https://devdocs.magento.com/guides/v2.3/javascript-dev-guide/javascript/custom_js.html

  • 1
    Accepting this solution as the answer as it worked for me. – nagaratna Feb 17 at 7:03

You can overwrite in design folder,


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.