4

Installing a Craft 3 plugin via Composer is pretty simple. You require the package, update Composer, and install it via the CMS.

My circumstances require that our company use a private Module on all projects. But installing the package via Composer always puts the Module into the default vendor directory.

So how can I install a module into the modules folder?

5

Craft Plugins require that a "type":"craft-plugin" property is defined in each composer.json file. Composer refers to this to help manage and install the plugin. Craft Modules do not currently have this support.

You can see all package types that Composer Installer supports here. There is still a way to achieve what you're trying to do though...

Composer Installers Extender allows you to create your own custom package type. So we could create craft-module ourselves. Just make sure your module has this "type":"craft-module" in it's composer.json

Now we can define some extra settings that tell Composer to put the modules into the modules directory. Incorporate the following into your projects composer.json file:

"require": {
  "oomphinc/composer-installers-extender": "^1.1",
  "vendorname/modulename": "dev-master"
},
"autoload": {
  "psr-4": {
    "modules\\": "modules/",
    "modules\\modulename\\": "modules/modulename/module/"
  }
},
"extra": {
  "installer-types": ["craft-module"],
  "installer-paths": {
    "modules/{$name}": ["type:craft-module"]
  }
},

Note: Make sure your module no longer exists in your vendor directory as you may be hit with some potential conflict warnings.

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.