9

In Magento2 I see different vendors follow different composer.json formats given below to name their modules.
1st:

 "autoload": {
    "files": [ "registration.php" ],
    "psr-4": {
      "Amit\\SamplePage\\": ""
    }
  }

2nd:

   "extra": {
        "map": [
            [
                "*",
                "Amit/SamplePage"
            ]
        ]
    }

1. What's difference between them and which one I should follow?
2. registration.php is used to to register a module then why composer.json is needed in all modules ?

12

This is the way to go:

"autoload": {
    "files": [ "registration.php" ],
    "psr-4": {
      "Amit\\SamplePage\\": ""
    }
  }

The map function in Composer:

   "extra": {
        "map": [
            [
                "*",
                "Amit/SamplePage"
            ]
        ]
    }

forces the extension to be installed in app/code. This was used in older beta's of Magento 2. Although this will work, it's not the way Magento loads extensions anymore. If you do not use the map function the extension will be installed in the vendor folder, as it should be.

registration.php defines the type: theme or extension and registers your theme/extension in Magento 2.

The composer.json file is added so the extension can be loaded via Composer. It also handles the autoloading for your extension.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.