Can somebody give me instructions when to run which compilation commands in Magento 2 developer mode? I'm not sure if I understand it right yet.
In the devdocs, developer mode is described as follows:
- Static view files are not cached; they are written to the Magento pub/static directory every time they’re called
Does that mean, each individual file in pub/static is generated when it is requested and you never need to call setup:static-content:deploy
? This contradicts my experience. Or can I delete any files and they will be regenerated? Also, images, CSS and JS files seem to be treated differently.
The developer mode documentation page says nothing about code compilation, but I think there was a difference as well, so it was not necessary to run setup:di:compile
after all changes in di.xml
files. Is this correct and if so, how does code generation work in developer mode?
In other words: cache aside, which commands do I need to run after which changes?
Best Answer
pay attention: I've experienced that in developer mode deleting the
pub/static
will break the mechanism because you get rid of the.htaccess
file that makes the magic in that folder.If you keep the
pub/static/.htaccess
file in developer mode you don't need to run any compilation command: Magento will create symlinks to files as soon as they are requested. That means that changes to static assets will be visible immediately, provided you also have cache disabled.You can delete the
pub/static/frontend
orpub/static/adminhtml
instead.In default mode assets are materialized in
pub/static
subfolder, meaning they are created (copied, not symlinked) at first request. If you modify them you have to flush the cache to have them updated.In production mode assets are not materialized (causing 404 HTTP error upon request) until you run the
bin/magento setup:static-content:deploy
command.Hope it helps.