0

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?

2 Answers 2

1

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.

1
  • It works for me.
    – Allen
    Commented Apr 1, 2021 at 10:32
2

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.

3
  • Hi, thank you for your comment.Follow your steps and i get an error.Warning: file_put_contents(E:\web/pub/static/frontend/ruby/ruby6/en_US/css/style.css): failed to open stream: No such file or directory in E:\web\vendor\wikimedia\less.php\lessc.inc.php on line 177
    – Allen
    Commented Mar 29, 2021 at 6:35
  • This doesn’t look like a default magento file, I guess you have a custom theme? I think it might be caused by incorrect file permissions, but I can’t be sure. You can run bin/magento static:content:deploy -f again to see if the file gets generated, but you shouldn’t have to in developer mode.
    – bernieu2
    Commented Mar 29, 2021 at 7:26
  • This really helped me, thanks! Commented Sep 9, 2022 at 0:21

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.