Programmatically create a taxonomy and attach a field to it I created a vocabulary using the following code.
$vocab = entity_create('taxonomy_vocabulary', array(
  'name' =&gt; 'vocab_name',
  'vid' =&gt; 'vocab_id',
  'description' =&gt; 'description'
));
$vocab-&gt;save();

I need to attach a custom field to it. I created the field with BaseFieldDefinition::create('string'), bu I couldn't figure out how to attach the created field to $vocab.
How can I achieve it?
Create them in the ui, export them to yaml using the single config export ui, put the yaml files in your_module/config/install - done