Question

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.

Was it helpful?

Solution

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

OTHER TIPS

You can overwrite in design folder,

app/design/frontend/Vendor/Theme/web/magnifier/magnifier.js
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top