A Vite plugin that transforms Twing.js templates into HTML with Drupal-specific features such as attributes, classes, and default attributes. Currently at version 1.1.2, released frequently with multiple fixes per month. It integrates Twing.js (a Twig engine for JavaScript) with Vite and provides hooks for Drupal-like theme initialization. Key differentiators: built-in Drupal attribute support, Storybook integration, and handling of Drupal-specific template patterns like classes array rendering and default attribute handling.
npm install vite-plugin-twing-drupalVerified import paths — ran on the pinned version, not inferred.
Shows how to configure the plugin with Drupal-specific functions, filters, globals, hooks, and options for Twing environment and loader.
Use only JavaScript-compatible Twig functions/filters.
Rename initEnvironment to Hooks in your plugin config.
Upgrade Vite to at least 4.4.11.
Use import syntax or dynamic import().
Install twing as a dependency: npm install twing
Add a hooks object with initEnvironment callback that creates a Twing environment.
Use import syntax: import vitePluginTwingDrupal from 'vite-plugin-twing-drupal'
Run: npm install twing
Declare custom functions in plugin config under functions option.