5

I would like to know that why we create compose.json and What is it use. Can someone briefly explain that to me?

company
--module
  composer.json
2

2 Answers 2

9

Magento 2 uses Composer, a PHP dependency manager, to package components and product editions.

Composer is a dependency management for PHP and in Magento 2, the composer plays the role in gathering components and product editions. When using the Magento 2 composer, there is no requirement of storing all code of each component, and you only need to create composer.json file and declare the needed components in that file instead that. Immediately, the composer will auto-define and take the corresponding data of those components to run for your project.

The Magento composer.json file defines the name, requirements, version, and other basic information about the component. This file must be placed in the root directory of the module.

Composer reads a composer.json file in Magento’s root directory to download third-party dependencies listed in the file.

The Component Manager uses the composer.json file in an extension’s root directory to perform the following actions:

The Component Manager can update, uninstall, enable, or disable an extension if installed using Composer (including from Packagist, Magento Marketplace, or other source) and it has a composer.json file. The Component Manager can still enable or disable an extension not installed using Composer (e.g. custom code) if it has a composer.json file.

Magento recommend you include composer.json in your component’s root directory even if you do not intend to distribute it to other merchants using Magento.

1
  • Described in a good way
    – RAKESH ROY
    Commented Jul 16, 2020 at 7:53
2

The composer.json file used to provide information about module, you can see difference between module that contain this file and module that not contain composer.json when using this "Module Manager" page

enter image description here

the Unknown modules not contain composer.json file

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.