
Code compilation
To compile the code in magento2, we use setup:di:compile command which performs the following tasks :
- Application code generation – for factories, proxies
- Interceptor generation – improve code generation of interceptors
- Interception cache generation – improve cache generation of interceptors
- Area configuration aggregation – improve dependency injection configurations per area
- Repositories code generation – create code for APIs
- Service data attributes generation – create extension classes for data objects
Switch to the magento root folder (it is generally public_html) and run the above command -
bin/magento setup:di:compile
The above command will show the output as below.
============================================
Compilation was started.
Plugin list generation... 9/9 [============================] 100% 46 secs 428.0 MiB
Generated code and dependency injection configuration successfully
============================================
The deployment commands of static view files enable us to write static
files to the Magento 2 file system. These static view files are located in Magento’s static directory (your
Magento2 install dir/pub/static) and some files are cached in your
Magento 2 install dir/var/view_preprocessed directory.
For deployment of static view files, follow these steps:
- Log in to your Magento 2 server as, or switch to, the Magento 2 file system owner.
- Delete the content under <your Magento install dir>/pub/static.
- Run the static view files deployment tool <your Magento install dir>/bin/magento setup:static-content:deploy.
Use the following commands to deploy static view files :
- cd pub/static && find . -depth -name .htaccess -prune -o -delete && cd ../..
- rm -rf var/cache/* var/view_preprocessed/* generated/* pub/static/* var/page_cache/* var/composer_home/*
- php bin/magento setup:static-content:deploy -f
- chmod -R 777 pub/static
Flush the magento cache using the above commands to make the site load fresh content -
- bin/magento cache:clean
- bin/magento cache:flush