Magento – setup:di:compile VS rm -f var/generation

dimagento2setup-di-compile

When we work in di.xml file for extend the functionality then we need to
php bin/magento setup:di:compile
setup:di:compile take 30 to 40 second or long in window.
if we remove the generation folder/files then it equal to run setup:di:compile or not ? kindly clear it because i read this in Magento 2 Book.
if rm -f var/generation then it save time.
I think it necessary to know for all beginner like me

Best Answer

yes, if you just run di:compile command, then it will override you current generated folder, it will delete all previous files and create new one.

But your directory need to have permission to delete through command, and also if files are currently in used (Through browser or anywhere else) it will show you error. But most of the time it will just delete old files and create new one in generated.

I got issues in my localhost, it will not delete files in generated, and shows error, but on my server (Ubuntu) it will work perfectly, so, I don't need to delete generated directory before running command

Related Topic