When you make a few Drupal sites, you will eventually find that you want to be able to take a feature that you created on one site and move it across to another site. After all, why re-invent the wheel!
My procedure for doing this has changed over time, using the features module was the way with Drupal 6 and Drupal 7, but with Drupal 8, we have better configuration management, and modules to help make things easier.
Features is again one of the modules that can be used, but I prefer a lighter approach, though its perhaps a little more work.
Start a new project as normal, but be sure to include config_devel.
Export all current config:
www-data@mytest:/code$ drush cex -y [success] Configuration successfully exported to /code/config-sync. /code/config-sync www-data@mytest:/code$
Create your new feature with as few changes as possible (so its easier to confirm the config files needed).
Check what config has been added or changed:
www-data@mytest:/code$ drush cst --state='Only in DB,Different' --field=name | awk '{ print " - " $1 }'
Create a new module directory with an info file in it, can be pretty basic:
www-data@mytest:/code$ cat web/modules/custom/myimage/myrichtext.info.yml name: My richtext. type: module description: "Provide richtext paragraph." core_version_requirement: ^8.8 || ^9
This is enough to now enable the module:
www-data@mytest:/code$ drush en myrichtext
The next step is to add the config_devel section to the info file and paste the output from the drush cst command above into it, something like this:
config_devel: install: - core.entity_form_display.paragraph.myrichtext.default - core.entity_view_display.paragraph.myrichtext.default - field.field.paragraph.myrichtext.myrichtext - field.storage.paragraph.myrichtext - paragraphs.paragraphs_type.myrichtext optional:
So the resulting file will be the combination of those:
www-data@mytest:/code$ cat web/modules/custom/myimage/myrichtext.info.yml name: My richtext. type: module description: "Provide richtext paragraph." core_version_requirement: ^8.8 || ^9 config_devel: install: - core.entity_form_display.paragraph.myrichtext.default - core.entity_view_display.paragraph.myrichtext.default - field.field.paragraph.myrichtext.myrichtext - field.storage.paragraph.myrichtext - paragraphs.paragraphs_type.myrichtext optional:
This then allows us to take use config_devel to keep the config files up to date:
www-data@mytest:/code$ drush cde myrichtext Exported config file modules/custom/myrichtext/config/install/core.entity_form_display.paragraph.myrichtext.default.yml. Exported config file modules/custom/myrichtext/config/install/core.entity_view_display.paragraph.myrichtext.default.yml. Exported config file modules/custom/myrichtext/config/install/field.field.paragraph.myrichtext.myrichtext.yml. Exported config file modules/custom/myrichtext/config/install/field.storage.paragraph.myrichtext.yml. Exported config file modules/custom/myrichtext/config/install/paragraphs.paragraphs_type.myrichtext.yml.
Congratulations, you've now created a component that can easily be copied across to other sites, and easily kept up to date if you do make some changes with a couple of easy commands.