- Issue created by @myriam_b
I don't know if it's your problem but Vite may uglify Drupal variable in your function, so you get a.t() in your uglified JS.
And Drupal.t() needs to remain Drupal.t() even uglified
https://drupal.stackexchange.com/a/284198/106294- ๐ฌ๐ทGreece axioteo
This issue doesn't appear to be caused by the Drupal module or Vite independently but rather seems to be a "side-effect" of using the two together. Specifically, as @daymoz pointed out, the problem seems related to how Vite performs JavaScript uglification and thus not respecting Drupal.t as a reserved function name. I was under the impression that Vite could be configured (using
mangleProps
etc in esbuild configurations) to exclude certain expressions or patterns from uglification, but any attempts to achieve this have not been successful so far.With this plugin, thereโs no need to extract locale variables into a standalone library excluded from Vite. Instead, you can continue to use
Drupal.t()
as you would in any other scenario. While the plugin hasnโt been extensively tested yet, it is functioning as expected in several local setups where weโve integrated the Drupal Vite module. Feel free to check it out, and let me know if any changes need to be made.Example usage and installation process:
https://www.npmjs.com/package/vite-plugin-preserve-drupal-t