2

When to use compile command in Magento 2.4

 bin/magento setup:di:compile

6 Answers 6

2

You 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.

0

The setup:di:compile command will perform the following things:

  1. Application code generation – for factories, proxies
  2. Interceptor generation – improve code generation of interceptors
  3. Interception cache generation – improve cache generation of interceptors
  4. Area configuration aggregation – improve dependency injection configurations per area
  5. Repositories code generation – create code for APIs
  6. Service data attributes generation – create extension classes for data objects

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.

0

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

0

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.

0

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

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.