This is from the documentation how to attach libraries to a render array of a block plugin and send php variables to js:
Attaching to a render array of a Block Plugin
To give another example of attaching a library to a render array, If
you are building a block plugin in your module, you can attach the
libraries to the render array in the build() function of your class
extending the BlockBase class (as of Drupal 8 beta 6).
'#theme' => 'your_module_theme_id',
'#someVariable' => $some_variable,
'#attached' => array(
'library' => array(
on some computed PHP information.
to Drupal 7's Drupal.settings). However, to make drupalSettings
had to do to make jQuery available: we have to declare a dependency on
So that then becomes:
$build['#attached']['library'] = 'fluffiness/cuddly-slider';
$build['#attached']['drupalSettings']['fluffiness']['cuddlySlider']['foo'] = 'bar';