Is it possible to di compile to specific module instead of whole magento di compile ?

Because, Whole Magento take a long time to compile. So, is it possible to di compile to specific module.

php bin/magento setup:di:compile CompanyName_ModuleName

Please help me. If it is possible.

2 Answers 2


You can do this by follow this step :

Go to :


Find this line :

$modulePaths = $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE);

Replace this below line and add path of the module which you want to compile like this :

$modulePaths = ['CompanyName_ModuleName' => '/var/www/html/YourMagento/app/code/CompanyName/ModuleName'];

Make sure module register with thisCompanyName_ModuleName in registration.php file.

It's temporary solution for di compile single module. Remove di generated module folder and refresh cache.

Hope, It will helpful for you.

  • Happy to help !! Happy Coding :) Jul 26, 2018 at 18:46
  • 3
    excellent work....Suggest to create a custom command and implement the this logic
    – Amit Bera
    Jul 26, 2018 at 19:39
  • 1
    Yes, a custom command that could be integrated in bin/magento or n98-magerun would be great Aug 1, 2018 at 11:46

If your focus is to try to contain as well as possible the downtime of your production, the below may help:

You could clone your codebase on the same server and separate folder (clone basically).

Once both environments would coexist, you can deploy static content on the clone without penalising the production environment uptime.

Finally, when the deploy is complete, you could either symlink the pub/static folder or just rsync. Of course, this may be done with a script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.