I have an Angular app I want to use as a Drupal 8 theme but when I try to attach it with a YAML file, Drupal doesn’t register that any JavaScript is being added to the theme.
ng.libraries.yml
base: version: 8.x css: css/styles.09e76a721be8ced0c439.bundle.css: {} js: js/inline.6375acbd4540ff168f58.bundle.js: {} js/polyfills.62cd0a749311c6ac36ca.bundle.js: {} js/vendor.d8949c111a4a3560f92d.bundle.js: {} js/vendor.d8949c111a4a3560f92d.bundle.js: {}
However, when I reference the script locations directly in my template, it works fine:
html.html.twig
<!DOCTYPE html> <html{{ html_attributes }}> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Hand of Death</title> <link href="themes/ng/dist/styles.09e76a721be8ced0c439.bundle.css" rel="stylesheet" /> </head> <body> <app-root></app-root> <script type="text/javascript" src="themes/ng/js/inline.cad96cf6be5b6cfb5176.bundle.js"></script> <script type="text/javascript" src="themes/ng/js/polyfills.62cd0a749311c6ac36ca.bundle.js"></script> <script type="text/javascript" src="themes/ng/js/vendor.d8949c111a4a3560f92d.bundle.js"></script> <script type="text/javascript" src="themes/ng/js/main.665799e3572bc9816ad1.bundle.js"></script> </body> </html>
From what little I can make sense out of the docs, somewhere I’m going to have to call Drupal.behaviors.myBehavior
, but that would not actually work in my situation.
Is there a way to get JavaScript to work without hardcoding it in the template?