0

I'm building my own theme to be used with Angular 4 and can't tell where/why Drupal is deciding to import jQuery.

Here's the code for my theme, loosely based off this Angular 1 theme:

ng.info.yml

name: ng
type: theme
libraries:
  - ng/base
description: 'An theme that makes Angular do all the work'
core: 8.x

ng.libraries.yml

base:
  version: 8.x
  js:
    js/inline.bundle.js: {}
    js/polyfills.bundle.js: {}
    js/styles.bundle.js: {}
    js/vendor.bundle.js: {}
    js/main.bundle.js: {}

ng.module

<?php
function ng_theme() {
  return array(
    'ng_view' => array(
      'template' => 'view',
      'variables' => array('title' => NULL),
    ),
  );
}

ng.routing.yml

ng.view:
  path: 'ng'
  defaults:
    _title: 'Drupal Angular'
    _controller: '\Drupal\ng\Controller\DrupalNgController::viewDrupalNg'
  requirements:
    _permission: 'access content'

src/Controller/DrupalNgController

namespace Drupal\ng\Controller;
use Drupal\Core\Controller\ControllerBase;
class DrupalNgController extends ControllerBase {
  public function viewDrupalNg() {
    $build['myelement'] = array(
      '#theme' => 'ng_view',
    );
    $build['myelement']['#attached']['library'][] = 'ng/inline.bundle';
    $build['myelement']['#attached']['library'][] = 'ng/polyfills.bundle';
    $build['myelement']['#attached']['library'][] = 'ng/styles.bundle';
    $build['myelement']['#attached']['library'][] = 'ng/vendor.bundle';
    $build['myelement']['#attached']['library'][] = 'ng/main.bundle';
    return $build;
  }
}

templates/view.html.twig

<html{{ html_attributes }}>
  <head>
    <title>Angular app</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="HandheldFriendly" content="true" />
    <meta name="apple-touch-fullscreen" content="YES" />
  </head>
  <body>
    <app-root></app-root>
  </body>
</html>
6
  • 1
    It's probably listed as a dependency of another library that's being included in the page. Dependencies are automatically included with their dependants
    – Clive
    Nov 3, 2017 at 14:19
  • A contributed module could be doing it too.
    – Kevin
    Nov 3, 2017 at 14:31
  • @Clive another JS library or Drupal? I'm not using it with any of my JavaScript
    – MMBB
    Nov 3, 2017 at 14:37
  • @Kevin looking through some of the default themes, I don't see them including jQuery, and so far, I haven't added anything outside of the core modules. Is jQuery a requirement for Drupal?
    – MMBB
    Nov 3, 2017 at 14:38
  • Well, something must be including it. It won't load unless explicitly asked for. Are you looking at the site anonymously?
    – Kevin
    Nov 3, 2017 at 14:49

2 Answers 2

0

Given you didn't install any contrib modules nor themes, dozens of Drupal core modules requires Jquery to function. You'll have to check what modules lists JQuery as a dependency. Search in core/modules and core/themes directories for core/jquery and you'll find out what module/theme is adding it and disable it.

For example "contextual" module needs it.

-1

Just add core/domready library to dependencies part of your theme libraries file: my_theme.libraries.yml

...
script:
  ...
  dependencies:
     - core/jquery
     - core/jquery.once
     - core/drupal
     - core/domready

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.