Project

General

Profile

Actions

Patch #44016

open

Add plugin support for registering ES modules and Stimulus controllers to importmap

Added by Takashi Kato 4 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Plugin API
Target version:
-

Description

The attached patches allow plugins to register standard ES modules and Stimulus controllers to the importmap.

Registered modules and controllers are accessible not only within the plugin itself but also from other plugins. This simplifies the use of third-party libraries distributed in ES module format. Since each module has an independent scope, naming conflicts between plugins are less likely to occur.

By defining module names in config/importmap.rb, you can import them as ES modules.
For standard modules, the plugin name is automatically added as a directory prefix to the module path. However, for Stimulus controllers, the plugin name is intentionally omitted to prevent HTML data attributes from becoming overly redundant.

Additionally, I have modified Redmine::PluginLoader to be instantiable for better testability.

Limitations:
The bin/importmap CLI has not been extended. Adding third-party libraries to vendor/javascript or similar directories must be done manually.

Example meetings plugin

conf/importmap.rb

# frozen_string_literal: true

pin "foo" 

pin_all_from "app/javascript/locales", under: "locales" 

pin_all_from "app/javascript/controllers", under: "controllers" 

Using registered module.

import {sample} from 'plugin_assets/meetings/foo'
import {lang} from 'plugin_assets/meetings/locales/ja'

smple()

Using registered stimulus controller.

<span data-controller="bar"></span>

Patches can be applied to r24621


Files

No data to display

Actions

Also available in: Atom PDF