Using Drush Shell-Aliases to Improve Config Workflow

Having to remember to disable every development module for every config export, and then re-enable them all after each export is not only annoying and time-wasting, but will almost never be done right every time.

After working with a Drupal 8 project for a while, I pulled some super useful commands from a project called Aquifer and converted them into Drush Shell-Aliases. These are super useful, and one of them handles this disabling/enabling of development modules for us automatically. Let's install them and see how it works.

Installing Drush Shell-Aliases

I have a contributed set of shell-aliases that I've used on a number of projects. You can can add them to your projects by simply requiring them with composer.

composer require "modules-unraveled/drush-shell-aliases:^1.0"

This will put them in the "drush/contrib" directory of our project. Since that's not a place drush will look by default, we need to tell drush that the shell-aliases exist. We'll do that in a "drushrc.php" file in the site-local drush folder.

Including the New Shell-Aliases In the Project

vi drush/drushrc.php

Paste in the following:

 * Load additional drushrc.php files
if (file_exists(__DIR__ . '/contrib/drush-shell-aliases/drushrc.php')) {
  include __DIR__ . '/contrib/drush-shell-aliases/drushrc.php';

  • Press escape
  • :wq (to save and close the file)

With that in place, you should be able to run drush @d8.loc statusss to make sure the new aliases are being picked up. If they are, you should see the output of drush status twice - with comments along the way.

Once you've confirmed they are usable, you can use the new "confex" alias which will disable development modules listed in a "mods_enabled.local" file, then export configuration, then re-enable the modules listed in "mods_enabled.local". Of course, we need to create that file first.

Creating a mods_enabled.local File

Creating the file is super simple. Just create a file named "mods_enabled.local" in the root of your project. Then list modules (by machine name) one per line.

vi mods_enabled.local

I'll add devel and devel generate


Exporting Config Without Development Modules

Now, we're all set! I'll enable devel manually to make sure it works.

drush @d8.loc en devel -y

Then use the new "confex" alias to do the heavy lifting.

drush @d8.loc confex

Watch as devel is disabled, a config export is performed, and then devel and devel_generate are enabled. No more worrying about development module config getting exported!

That's just one of the aliases that comes in that file. Feel free to try out the rest, and look for a future blog post/series coving them all.