I am trying to add a new view to an existing module. I created the view using Views UI and exported its YML to the 'config/optional' folder. If I install the module for the first time, the view is enabled in Views UI.
When I add the view to an existing site, it won't activate no matter what I do. I've tried clearing caches, looked for examples in core & contributed modules and searched the documentation for possible hook_update examples. The only thing I found was in 'Create or update a View' section at https://www.drupal.org/docs/7/creating-custom-modules/howtos/examples-for-database-update-scripts-using-hook_update_n-how but it's for Drupal 7. The PHP code looks like it would work for Drupal 8 but I haven't been able to find a way to export a view as code.