Magento 2 Enterprise – Create New Module in Vendor Directory

composermagento-enterprisemagento2module

I tried to create new module in vendor directory in Magento Enterprise 2.0.0.
The module could not be loaded after I ran the Magento setup:upgrade.

If I move my files to the app/code directory, the module will be set up successfully.

For Magento 2 Enterprise edition, all modules are in vendor directory but Community edition uses app/code directory. I wonder if it is possible to create custom module in the vendor directory. If yes, what are the differences between creating a custom module in app/code and vendor.

vendor/Test/Testing/registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Test_Testing',
    __DIR__ );

vendor/Test/Testing/composer.json

{   "name": "test/testing",   "description": "Testing",   "require": {
    "php": "~5.5.0|~5.6.0|~7.0.0",
    "magento/framework": "100.0.*"   },   "type": "magento2-module",   "version": "0.1.0",   "license": [
    "proprietary"   ],   "autoload": {
    "files": [ "registration.php" ],
    "psr-4": {
      "Test\\Testing\\": ""
    }   } }

vendor/Test/Testing/etc/module.xml

<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Test_Testing" setup_version="0.1.0">
    </module> </config>

Best Answer

Custom modules should not be developed in vendor directory. Copy content from vendor/magento/magento2-base to the root of the project, create custom .gitignore as described here and initialize new git repository. Then develop custom module under app/code/VendorName/ModuleName.

Later, when you decide to distribute the module, it will have to be packaged and published. When someone will buy/install your module, it will be automatically installed by composer to vendor directory of their project.

Related Topic