title: How to add a new field to a content type in drupal 8 module?
body: <p>I have module, where i want to create new taxonomy field (if not exist) and attach it to the content type. I found easy way by exporting fields, but it will work only when I install module. I need to create them from time to time, automatically.</p>
  
  <p>So by now I can create vocabulary and taxonomy terms:</p>
  
  <pre><code>$vocabulary = \Drupal\taxonomy\Entity\Vocabulary::load($vid);
  if (!$vocabulary) {
      $vocabulary = \Drupal\taxonomy\Entity\Vocabulary::create(array(
            'vid' =&gt; $vid,
            'machine_name' =&gt; $vid,
            'name' =&gt; $name,
      ));
      $vocabulary-&gt;save();
  }
  </code></pre>
  
  <p>create taxonomy term: (BTW is there some better way to check if term exist? taxonomy_term_load_multiple_by_name is old d7 function, but i cant find other way)</p>
  
  <pre><code>if($terms = taxonomy_term_load_multiple_by_name($name, $vid))
  {
      $term = reset($terms);
  }
  else
  {
      $term = \Drupal\taxonomy\Entity\Term::create([
          'name' =&gt; $name, 
          'vid' =&gt; $vid,
      ])-&gt;save();
  }
  </code></pre>
  
  <p>Node entity has only metod to check field definitions, and i cant find any possibility to create/attach field. I found only toturials and code examples to create brand new type of field, but no glue how to attach fields to a content type.</p>