JavaScript dependencies for a specific block or page I am migrating a Drupal 7 site to Drupal 8.  I have a custom block (visible only on the home page) that has some tabs on it.  Currently, the tabs are implemented using jQuery UI tabs and it would be nice (but not necessary) to keep them using that.

In order to get this to work, I need to use the jQuery and jQuery UI JavaScript files.  However, everything I have seen online talks about module and theme dependencies.  There doesn't seem to be any way to tell Drupal 8 that a specific block (or page, etc.) needs specific JavaScript files loaded in order to work correctly.

I know that I can just import the javascript files directly with script tags, but that doesn't seem to be the preferred method, especially considering all of the various optimizations that are part of Drupal (to make sure that a file is only included once, for example).

How do I include the required JavaScript files (available in core) on a specific page or as part of a specific block?

I don't really want to create a custom module for every time that I need to do this, but all of the references I have found online talk about dependencies for themes or modules, nothing for specific content.

EDIT: Multiple suggested answers involve PHP, custom modules, YML, etc.  These are not what I am looking for.  I am looking for a solution for front-end content creation (pages, nodes, blocks for the "custom block library", and so on), not requiring back-end coding and development.  Modules on Drupal.org that allow this to be done generically are perfectly acceptable.  Maybe I need to create one and put it up there, but I would think there should be an existing solution by now.  It seems strange to me that there isn't, but maybe I'm missing something.
Define an asset library in mymodule.libraries.yml. An asset library can declare either CSS assets or JavaScript assets, or both. It can also declare dependencies on other asset libraries. For example on jQuery (core/jquery) or perhaps your JavaScript defines a "Drupal behavior", in which case you depend on the supporting infrastructure for that (core/drupal). Ex:

example_library:
  js: path/to/some/file.js: {}
  dependencies:
    - core/drupal
    - core/jquery

Use #attached in your block's render array to attach the asset library:


// Assuming the variable containing your render array is called $build.
$build['#attached']['library'][] = 'mymodule/example_library';


Extensive documentation can be found at https://www.drupal.org/docs/8/creating-custom-modules/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-module.