The perfect Magento 2 setup for development

Please note: This article is work in progress!

 

I had the pleasure to attend MageUnconference again this year (thanks to Modulwerft – Simon Sprankel for the ticket btw!). As usual for an Unconference, we collected the topics for our daily programme in the morning. Out of some discussions I had with Matthias at the office regarding the easiest/best/most painless way to set up an environment for M2 module development, we decided to put this as a topic on the wall for voting and discussion with other attendees.

A few minutes and a lot of votes later, we’ve found ourselves in a packed room full of developers who wanted to hear and discuss with us about this topic as well.

Spoiler: You’re maybe not gonna find the perfect Magento 2 setup for module development in this article. This is a collection of things that can be useful for your setup and what we discussed during our session at MageUnconference.

Out of scope: This article is not about setting up a new project with Magento 2. I do only focus on the development of a single module here.

 

Various M2 module development methods

Seperate Repository

The first method I’d like to share here is the method of setting up a single repository for your new module: This can either be a local repository or a remote one on GitHub/Bitbucket.

Add this module to your composer.json just as any 3rd party module and you’re good to go.

{
    "require": { "avoelkl/mymodule": "*" },
    "repositories": [
        {
            "type": "git",
            "url": "https://github.com/avoelkl/mymodule.git"
        }
    ]
}

Positive:

+ Easy way to start and set up

+ There’s only the need to add your module to composer.json, no additional registration/modification needed.

Negative:

– You have to do a lot of git commits/push/pulls/composer updates for your changes to take effect

– You’ll generate a lot of unneccessary commits during development (especially if you’re new to M2 development and trying out some stuff)

 

Working in the vendor dir

This approach it pretty straight forward: Set up a new Git repository, add it to the composer.json and run composer update. You’ll find your module files in the vendor directory afterwards, where you can edit them.

While I personally do not prefer this method as it feels rather dirty to me, applying changes and developing directly in the vendor folder seems not to be so unusual among Magento developers present in the MageUnconference session.

Positive:

+ no need to commit every change to test it

Negative:

– It’s not very obvious where the extension development happens.

– When someone else/you decide to remove the vendor folder completely (which should not be a problem usually, as you can always get the recent packages via composer install/upadte), you will lose all your uncommitted changes.

At least composer warns you if you have got modified content in the vendor dir when running a „composer update“ so you don’t lose your changes without confirming before.

Symlink to your module

Another easy way, which requires no Git repo at all to get started (but seriously, who wants that?) is to create a symlink in app/code to your module files outside the Magento folder structure.

 

You could also be interested in including a local repo via composer path https://getcomposer.org/doc/05-repositories.md#path

{
    "repositories": [
        {
            "type": "path",
            "url": "../../avoelkl/mymodule",
            "options": {
                "symlink": false
            }
        }
    ]
}

Folder Structure

From Magento 1 we’re used to work with our own folder structures and symlink them later via modman file.

Most of the current M1 modules I know either have the `app/` folder directly in their extension repo or a `src/` folder above them:

Version 1:

  • app/ modman

Version 2:

  • src/
  • src/app
  • test
  • modman

It seems to me (from what I can see in the official Magento 2 sample modules) that such a folder structure is not the default somewhat suggested, I think this is not very flexible.

  • .git
  • Block/
  • etc/
  • Model/
  • Observer/
  • view/
  • registration.php
  • composer.json

Different Ways of Setups

Fabian Schmengler (@fschmengler)

Fabian explained his current structure during the session.
The folder structure looks like this:

/var/www/m2.local/MyExt <= this folder also contains the .git dir

registration.php & Subfolders

/var/www/m2.local/MyExt/registration.php
/var/www/m2.local/MyExt/src
/var/www/m2.local/MyExt/test


Daniel Falke (@flyingmana)

https://github.com/Cotya/DashboardProject

David Verholen (@david_verholen)

https://github.com/davidverholen/magento2-dynamic-component-registry

Max Pronko

Max wrote a Blogpost about how to develop a Magento 2 module with modman

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.