When to use compile command in Magento 2.4
bin/magento setup:di:compile
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityYou would typically run the bin/magento setup:di:compile
command when you have made changes to the DI configuration of your Magento application, or when you have installed new modules that include their own DI configurations. Running this command will ensure that the updated DI configuration is compiled and ready to use.
It's also a good idea to run this command after you have deployed your Magento application to a production environment, as it can help improve the performance of the application.
Keep in mind that running this command can take some time, especially if you have a large number of modules and a complex DI configuration.
The setup:di:compile command will perform the following things:
If the compilation process starts taking more time than it should, it is likely that you need to run setup:di:compile command.
The compilation process basically slows down when developers make lots of changes in proxy js, factory methods, or just about any code.
So, if you believe you’ve made an abundance of changes in your project and seeing a slow down in compilation process speed, it’s probably time to execute setup:di:compile command.
However, you can also use the setup:di:compile command for a specific module.
When developers make lots of changes in proxy js, factory methods, or just about any code. So, if you believe you've made an abundance of changes in your project and seeing a slowdown in compilation process speed, it's probably time to execute setup:di:compile
command.
But If you made changes like add a new dependency in __construct() or changes in di.xml or class , factory method, you need to delete the changed files from var/generation folder or run this command
The above s:d:c command basically generates the contents of var/di folder in Magento. According to the official Magento docs, it compiles code like Factories, Proxies, Interceptors, etc. and puts them in generated or var/generation directory. Due to these what changes we have made it will reflects over there.
The setup:di:compile command is an integral part of Magento’s 2 command-line interface (CLI). Its primary purpose is to compile the dependency injection (DI) configuration files