Skip to content
GitHub

Vite DevTools

An accessibility audit and a Drupal template picker in Vite DevTools, and port takeover for the dev server.

uebertool() turns on Vite DevTools in dev and adds two entries to its dock. Drupal pages load the dock through the theme's vite library, next to @vite/client.

To turn it off:

vite.config.ts
uebertool({
  devtools: false,
})

The Framework category (Vite+ with Vite, Rolldown, Vitest and Oxc) is hidden by default. Switch it back on in the dock's settings; that choice is kept.

The Rolldown build data in DevTools is only recorded if you set build.rolldownOptions.devtools: {} yourself.

Run A11y Check

Runs axe-core on the current page and lists each violation in the messages panel, with its WCAG criteria as labels. Outline draws boxes around the offending elements; click it again or press Esc to remove them.

Drupal Picker

Highlights the SDC component or Twig template under the cursor. ↑ and ↓ move to the surrounding or inner template, and Enter opens the file in your editor. A component whose Twig only extends the sdc-custom-element bridge opens its script instead.

Click to select a template. The selection stays put and a panel shows:

  • the template's path,
  • the tags from the template's markup down to the clicked element, e.g. div > p,
  • Parent to select the surrounding template, and Open to open the file,
  • Info with the theme hook and the whole chain of templates around the selection. Click an entry to select it.

The selection stays on the picked element until you close the panel. Clicking outside the panel leaves the picker. Esc or the panel's close button clears the selection so you can pick again, and a second Esc leaves the picker. The file opens at its first line: Drupal's debug output names the template, not the line that printed an element.

The picker reads Drupal's theme debug comments, so Twig debug has to be on:

services.yml
parameters:
  twig.config:
    debug: true

Drupal only prints those comments for templates rendered for a theme hook. To also pick templates pulled in with {% include %} or {% embed %}, enable uebertool_twig from the companion module. In debug mode it adds the same comments around them, with a 📎 badge, and the picker labels them "included template". SDC components are left out because core already marks them, and so are missing ignore missing targets and non-Twig files such as SVGs. Production output does not change.

Outside a container, the file opens in $EDITOR. Inside the DDEV web container, Vite cannot reach your editor, so the browser opens an editor URL instead:

vite.config.ts
uebertool({
  devtools: {
    picker: {
      // `{path}` becomes the file's absolute path on the host.
      editorUrl: 'vscode://file{path}:1',
      // Host path of the project. Read from DDEV by default.
      hostRoot: '/home/me/Sites/project',
    },
  },
})

Port Takeover

Always on, unlike the dock it is not part of DevTools. If a dev server for the same theme is still running, for example in a forgotten terminal, a new vite stops it and takes over its port. Without this, strictPort would just fail.

Each dev server records its PID in node_modules/.cache/uebertool/vite-<port>.lock. On start, Vite checks the lock for the port it is about to use and sends the server recorded there SIGTERM. If that server has not exited and freed the port after 10 seconds, it gets SIGKILL. Servers of the same theme on different ports leave each other alone.

Only a server recorded in that lock is ever stopped. Anything else on the port, including a dev server started before this feature existed, is left alone, and Vite fails with Port … is already in use. A lock written inside the DDEV container is ignored on the host, and the other way round, because process IDs differ between the two.