Learn how to clear the Magento directory during its whole development process in this blog.
When you are extending the Magento theme or module, your fast-changing environment needs you to periodically clear certain directories and cache. Or else, your code runs with exception and won’t function properly.
Clear Magento Directory During Its Development
There are some cases that will clear the Magento directory to make a code even clearer,
You must clear these directories var/di, var/generation for
- Change a class if there is a plug-in related to it.
- A change that results in generated factories or proxies
To change any di.xml
var/generation, It also runs the code compiler again
For add, remove, disable, enable the module
var/di, var/generation, var/cache, var/page_cache
For edit layout or theme
var/view_preprocessed, var/cache, var/page_cache
To change LESS or templates
var/view_preprocessed, var/cache, var/page_cache as well
Add or edit a CMS page, cache blocks, or use Magento admin to change the configuration.
You can also use the following command-line tools to clear some directories for you
Magento setup: Upgrade
This tool upgrades the Magento database scheme and data using
This generates code
Magento deploy:mode: Set
It changes developer mode to production mode and vice versa
var/di, var/generation, var/view_preprocessed
Magento cache: Clean
It cleans the cache using var/cache, var/page_cache
The following cases will provide guidelines to clear the Magento directory during the development of Magento 2.