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?
4 Answers 4
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 or pub/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.
-
-
@Erfan what do you mean more precisely?Alessandro Ronchi– Alessandro Ronchi2016年12月26日 11:03:32 +00:00Commented Dec 26, 2016 at 11:03
-
2The question also queries about the effect of the deploy mode on DI compilation. I just did a quick test, and if you're in developer mode, you don't need to compile DI in order for your changes in
di.xmlto show up (seems code generation is done on the fly per page-hit?) Anyhow, thought it'd be a good addition to your already good answer!Erfan– Erfan2016年12月27日 02:30:11 +00:00Commented Dec 27, 2016 at 2:30 -
You are right @ErfanAlessandro Ronchi– Alessandro Ronchi2016年12月27日 08:12:49 +00:00Commented Dec 27, 2016 at 8:12
-
1+ Thanks brother. Worked like a charm. I had a very bad experience executing deploying commands repeatedly in order to get my changes from less to css even in developer mode. I copied .htaccess from another project and pasted at the mentioned location. Khalaaas!Umar Yousaf– Umar Yousaf2017年11月27日 20:18:20 +00:00Commented Nov 27, 2017 at 20:18
Just to clarify between the three different modes (source: Magento U Fundamentals course). In bold, the specific points related to your question.
Developer mode
- Static file materialization is not enabled.
- Uncaught exceptions displayed in the browser
- Exceptions thrown in error handler, not logged
- System logging in
var/report, highly detailed.
You should use the Developer mode while you are developing customizations or extensions. The main benefit to this mode is that error messages are visible to you. It should not be used in production because of its impact on performance. In Developer mode, static view files are generated every time they are requested. They are written to the
pub/staticdirectory, but this cache is not used. This has big performance impact, but any changes a developer makes to view files are immediately visible.Uncaught exceptions are displayed in the browser, rather than being logged. An exception is thrown whenever an event subscriber cannot be invoked.
System logging in
var/reportis highly detailed in this mode.
Production mode
- Deployment phase on the production system; highest performance
- Exceptions are not displayed to the user -- written to logs only.
- This mode disables static file materialization.
- The Magento docroot can have read-only permissions.
You should run Magento in Production mode once it is deployed to a production server.
Production mode provides the highest performance in Magento 2.
The most important aspect of this mode is that errors are logged to the file system and are never displayed to the user. In this mode, static view files are not created on the fly when they are requested; instead, they have to be deployed to the
pub/staticdirectory using the command-line tool. The generated pages will contain direct links to the deployed page resources.Any changes to view files require running the deploy tool again.
Because the view files are deployed using the CLI tool, the web user does to need to have write access. The Magento
pub/staticdirectory can have read-only permissions, which is a more secure setup on a publicly accessible server.
Default mode
- Used when no other mode is specified
- Hides exceptions from the user and writes them to log files
- Static file materialization is enabled.
- Not recommended / not optimized for production: caching impacts performance negatively.
As its name implies, Default mode is how the Magento software operates if not other mode is specified.
In this mode, errros are logged to files in
var/reportsand are never shown to a user. Static view files are materialized on the fly and then cached.In contrast to the developer mode, view file changes are not visible until the generated static view files are cleared.
Default mode is not optimized for a production environment, primarily because of the adverse performance impact of static files being materialized on the fly rather than generating and deploying them beforehand.
In other words, creating static files on the fly and caching them has a greater performance impact than generating them using the static file creation command line tool.
from my experience, you don't need to run any commands for code / static-file generation in developer mode.
If the static files were not generated, there might be another issue.
I see two reasons for that on first sight:
- developer mode is not working correctly. maybe the activation failed for some reason
- the rewrite for static files on the pub/static.php is not working
-
1My less file in pub/static not re-generate. Do you get this problem. How to make it auto-regeneratemrtuvn– mrtuvn2016年03月21日 05:32:40 +00:00Commented Mar 21, 2016 at 5:32
-
It's important that the developer mode is active and also taht rewrites are working, since any request to static files is rewritten to pub/static.php first which then generates the file (in developer mode) under pub/static if it is not already presentDavid Verholen– David Verholen2016年03月23日 13:40:24 +00:00Commented Mar 23, 2016 at 13:40
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?
Yes. But according to my experience this doesn't work most of the time. Might be a bug. Better solution is to delete pub/static content and deploy static content again whenever you changed static file(js, css, html, etc.) even you have already activated developer mode.
My own question about this.
-
It depends the way you see it. If you want to run setup:static-content:deploy everytime you make a change, it will take you years to finish a project cause basically you're creating every single file for your store when you're only updating one file. So, my solution was to overwrite the files within pub/static and clearing cache to see my changes. Once I'm happy with my results then I'll go to my theme or custom module files to overwrite my main files and then run setup:static-content:deploy to update my static files.Wolfgang Leon– Wolfgang Leon2017年01月17日 13:38:29 +00:00Commented Jan 17, 2017 at 13:38
Explore related questions
See similar questions with these tags.