I am modifying the js or html file in my localhost. I have to execute it every time.
php bin/magento setup:static-content:deploy -f
php bin/magento indexer:reindex
php bin/magento cache:clean
Is there any way to not compile it every time?
All files are linked to your pub/static
folder. You can modify the deployed
file in there.
For example: Catalog/view/frontend/web/js/catalog-add-to-cart.js
will be in pub/static/frontend/Magento/luma/en_US/Magento_Catalog/js/catalog-add-to-cart.js
This example assume you are using default Luma theme
The pub/static folder is generated
so remember to save your changes into original file, otherwise, it will be clear after running deploy command.
Set developer mode
bin/magento deploy:mode:set developer
When developing, I make sure full_page cache is off. Usually, I also turn off block and layout cache too
bin/magento cache:disable full_page layout block_html
Usually you should see js or html changes immediately if those are off and developer mode set.
For css/less changes, you should remove static files. In developer mode, all these files are automatically recreated.
rm -rf pub/static/frontend/*
Run those commands from magento2 root folder. Note - do NOT delete pub/static/.htaccess file as it is necessary.