3

I am creating one module which will contain more then 1 module in it. Is it possible to create single composer file for more then 1 module?

Please let me know is it possible or not. If yes, then it will be more helpful if you can tell me how.

1 Answer 1

4

Yes, with the following directory structure:

- composer.json
- registration.php
- module1/
- module2/

composer.json contains the reference to registration.php as usual.

In registration.php you define the source directories for both modules:

<?php
namespace {
    \Magento\Framework\Component\ComponentRegistrar::register(
        \Magento\Framework\Component\ComponentRegistrar::MODULE,
        'Company_Module1',
        __DIR__ . '/module1'
    );
    \Magento\Framework\Component\ComponentRegistrar::register(
        \Magento\Framework\Component\ComponentRegistrar::MODULE,
        'Company_Module2',
        __DIR__ . '/module2'
    );
}

The directories module1 and module2 contain the rest of the source files for each module.

4
  • Would this also work modules placed in the "vendor" directory, installed from a custom composer repository?
    – Brett
    Apr 16, 2017 at 12:19
  • Yes, actually this only works for composer installed modules, I assumed you were asking for that. For modules in app/code you need two separate registration.php files Apr 16, 2017 at 13:28
  • Should I keep registartion.php, module1 & module2 inside Vendor folder? Apr 17, 2017 at 11:58
  • I don't understand the question. If you install the package with composer, all will be placed within the vendor directory and you shouldn't change anything there Apr 17, 2017 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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