When would you place a module in the app/code folder versus another
location?
If I add new module in app/code folder
with composer.json
and another module in vendor folder
using composer
What will be the difference ?
- I am aware about that if module is in
vendor folder
then It can be
updated by composer. - Does that same thing apply with the module which is in
app/code
?
folder - When you update module which is in
app/code folder
usingcomposer
they install in vendor directory.
So, What is the point of
Composer.json
inapp/code
folder Module ?
Best Answer
As you already pointed out, composer is a package management tool. Any external modules/packages which constitutes your Magento application will be managed by the composer and will be available under
vendor
directory, provided you have adopted the composer way of installation/ updating of your Magento instance. Magento core modules are also treated as external packages which constitute your Magento application.app/code
expects those Magento modules which are "unique" to your Magento application. Those jobs or customization which we cannot achieve by a third party/external modules has to be here. In most of the time, these modules are not installed or updated using composer. In most of the projects, your version system generally holds and manage yourapp/code
folder only (There are other folder files we need to keep inside a versioning system, but none of them as relevant as modules insideapp/code
.But it is a good practice to keep a
composer.json
file for those modules too. Reasons are many:If you need more details of composer.json files which are using in Magento, you can follow this official documentation about the composer.json file.