Hello everyone. Clear Directories during Development in Magento 2

While you’re developing Magento modules or themes, your rapidly changing environment requires you to periodically clear certain directories and caches. Otherwise, your code runs with exceptions and won’t function properly.

In this blog, I will show you some cases and you must clear the directory to make the code work.

Case 1:

Change a class if there is a plug-in related to it.

A change that results in generated factories or proxies (for example, a non-existent factory declared in a class or a proxy declared in di.xml)

Clear : var/di, var/generation

Case 2:

Change any di.xml

Clear : var/di, var/generation; also, run the code compiler again

Case 3:

Add, remove, enable, or disable modules

Clear: var/di, var/generation, var/cache, var/page_cache

Case 4:

Add or edit a layout or theme

Clear: var/view_preprocessed, var/cache, var/page_cache

Case 5:

Change LESS or templates

Clear: var/view_preprocessed, var/cache, var/page_cache

Case 6:

Add or edit a CMS page, cacheable block, or use the Magento Admin to change the configuration

Clear: var/cache, var/page_cache

Command line to clear:

rm -rf <your Magento install dir>/var/di/* <your Magento install dir>/var/generation/*

The steps I mention above is the shortest process for you to Clear Directories during Development in Magento 2.

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

Prompt Widget in Magento 2
How to Run Enable/Disable Maintenance Mode in Magento 2

Leave a Reply

Your email address will not be published. Required fields are marked *