Currently, the scripts.js file that ships with Basic does not load because it is not added through a theme library. This could potentially be confusing for anyone starting out with the theme. To get this file loading globally, as is, the file has to be added to the global library along with dependancies on core/jquery and core/drupal:

global:
  version: VERSION
  css:
    base:
      css/base/base.css: {}
    layout:
      css/layout/layout.css: {}
    component:
      css/components/components.css: {}
    theme:
      css/theme/theme.css: {}
      css/theme/print.css: { media: print }
  js:
    js/modernizr.js: {}
    js/build/scripts.js: {}
  dependencies:
    - core/jquery
    - core/drupal

Just wanted to capture this issue here for anyone who encounters this and needs a quick fix.

Moving forward let's think about:

  • When working with Drupal libraries, is using a global scripts file something we want to encourage? Is it best practice? Ideally, JS and corresponding dependencies would only load on pages where they are required.
  • Keeping in min, as a starter theme, we want to keep things easy.
  • This JS file was moved over directly from the D7 version. It seems to be formatted differently than the JS files in the "seven" theme. Do we have legacy code in place here? Is this format still relevant for D8?
  • Comments in scripts.js could use some work once we determine a best practice.
  • On a quasi related note, are there benefits to haveing Grunt compiling minified JS from the "source" folder to the "build" folder. I think core does this as well, correct?

Let me know if you have any thoughts!

Cheers, Leah

Comments

leahtard created an issue. See original summary.

joelpittet’s picture

Drupal doesn't need jQuery so you'd have to add both. Sorry thought they may be dependent on eachother.

leahtard’s picture

Thanks Joel! I tested and confirmed the same thing. Our scripts file will require both "core/jquery" and "core/drupal".

I will now be committing an update that includes docs in README.txt for the js folder. I have also added scripts.js to basic.libraries.yml but commented it out. This way, we do not enable it by default, but it is clearer what is needed to enable it.

Cheers, Leah

  • leahtard authored b7983af on 8.x-1.x
    Issue #2675764 by leahtard, joelpittet: Improved documentation for the...
leahtard’s picture

Component: Code » Documentation
Status: Active » Fixed
leahtard’s picture

Status: Fixed » Closed (fixed)
joelpittet’s picture

Heads up, after two weeks as 'fixed' it will turn itself to closed fixed. Automated:)

leahtard’s picture

Ha! Thanks, didn't know that. I was cleaning up today :)

joelpittet’s picture

I noticed! Thank you:) leahtard++