Today I will show you how to create composer.json file to upload your Magento 2 extension to Magento Market Place.
Let’s start to create composer.json file to upload your Magento 2 extensions in following steps:
- Understanding the composer package structure
- Understanding your package
- Fill in your composer.json file by data
As you know Composer is a dependency manager for PHP. Magento 2 uses Composer to package components and product editions.
In the code base, some third-party components that the Magento system uses might not be present . And in the root composer.json file, they are listed as dependencies .Moreover, the Component Manager looks for a composer.json in a component’s root directory might perform actions on the component as well as its dependencies.
Composer Package Structure
You can see in the image bellow to see the structure of composer:
And here is the package:
Now let’s start to work with composer.json file!
The name of the package. It consists of vendor name and project name, separated by /. Example: magestore/module-bannerslider
Required for published packages (libraries).
A short description of the package. Usually this is just one line long.
The version of the package.this is not required and should be omitted (see below) in most cases . However, you should have this field to upload the package to the marketplace.
This might follow the format of X.Y.Z or vX.Y.Z with an optional suffix of -dev, -patch (-p), -alpha (-a), -beta (-b) or -RC. By a number, The patch, alpha, beta and RC suffixes might also be followed .
The authors of the package. This is an array of objects.
Each author object can have following properties:
- name: The author’s name. Usually their real name.
- email: The author’s email address.
- homepage: An URL to the author’s website.
- role: The author’s role in the project (e.g. developer or translator)
The license of the package. This can be either a string or an array of strings.
The recommended notation for the most common licenses is (alphabetical):
The type of the package. It defaults to library. In Magento 2 extension, it should be magento2-module
Autoload mapping for a PHP autoloader.
In the Magento 2 extension, you can use psr-4.
After creating the composer.json by this guide, please compress all the file and the folder include the composer.json to the .zip file.
It is the package which you can upload to the Marketplace.
Visit our website for more information CartMigration