Move your M2 extension to the vendor dir




In my recent Imagine presentation I talked about keeping your Magento 2 extensions in the vendor folder. The good news is that it is fairly straight forward to convert your extension from one location to the other. Especially if you wanted to quickly trial something out first, there is no harm in developing under app/code, and only once you are ready to move from your local environment to a staging environment convert it into a Composer package.

cd app/code/Fooman/Example
git init
git add -A
git commit -m 'Initial commit'
#The below example uses Bitbucket but you can just as well use a local path to an existing empty git repo
git remote add origin ssh://git@bitbucket.org/fooman/extension-example.git
git tag v1.0.0
git push -u --tags origin master

cd ../../../../ 
#Magento Root folder
composer config repositories.fooman-example vcs git@bitbucket.org:fooman/extension-example.git
composer require fooman/example-m2:1.0.0 --prefer-source
rm -rf app/code/Fooman/Example

Done.

In case you need to keep working on the extension:

cd vendor/fooman/example-m2
#work
#update version number in composer.json to 1.0.1 (this is a Magentoism as technically Composer considers the git tag the version number but Magento's Setup Wizard will read the version number from the composer.json file
git add -A
git commit
git tag v1.0.1
git push --tags

update the main composer.json with

cd ../../../
composer require fooman/example-m2:1.0.1
Kristof Ringleff

Kristof Ringleff

Founder and Lead Developer at Fooman

Join the Fooman Community

We send our popular Fooman Developer Monthly email with Magento news, articles & developer tips, as well as occasional Fooman extension updates.