Adding JS to a Drupal 8 theme (replacement for drupal_add_js) In Drupal 7, I can use drupal_add_js within a theme's template.php file as a theme_preprocess_html(&amp;$vars) function:

   drupal_add_js(drupal_get_path('theme', 'mytheme') . '/js/scripts.js',
        array(
          'group' =&gt; JS_THEME,
          'preprocess' =&gt; TRUE,
          'weight' =&gt; '999',
        ));

  $vars['scripts'] = drupal_get_js();


In Drupal 8, I've tried converting this using attached in my theme's .theme file as such:

  $vars['#attached']['js'] = array(
    array(
      'data' =&gt; drupal_get_path('theme', 'mytheme') . '/js/scripts.js',
      'options' =&gt; array(
        'group' =&gt; JS_THEME,
        'preprocess' =&gt; TRUE,
        'every_page' =&gt; TRUE,
      ),
    ),
  );


... but that did not work and there were no errors in watchdog / console or otherwise.

According to the D8 API page for drupal_add_js:


  Deprecated - as of Drupal 8.0. Use the #attached key in render arrays
  instead.


There was not much more info that that however. It seems that drupal_add_css will also use this method. I know it's still early days for Drupal 8 but I was hoping to get a jump on this.
It seems you can use hook_preprocess_page with attached as such:

function MYTHEME_preprocess_page(&amp;$vars, $hook) {
  $path = drupal_get_path('theme', 'MYTHEME');
     // Render the main scripts file.
  $local_js = array(
    '#attached' =&gt; array(
      'js' =&gt; array(
        $path . '/js/scripts.js' =&gt; array(
          'group' =&gt; JS_THEME,
          'weight' =&gt; 9999),
      ),
    ),
  );
  \Drupal::service('renderer')-&gt;renderRoot($local_js);
}


This works great (theme.inc uses this method), note the extra nested array around the weight.