Topic on Talk:ResourceLoader/Package files

Cavila (talkcontribs)

Sometimes an external js library used in an extension can be extended with many optional plugins, which may or may not use require() functions. I would imagine that (a) the library can be added to the "packageFiles" of the main module (so it can be imported/required in the main entry file) and that (b) a list of plugins would be added, under "scripts", to a separate 'plugin module'. If you then want to add the plugin module to packageFiles, which approach would be best/recommended if at all possible?

  • the config option, pointing to the module within extension.json (if self-referentiality is at all possible), or
  • the PHP callback option, pointing to a function that somehow returns the RL module.

Or is there a better and more straightforward approach I'm overlooking?

Tacsipacsi (talkcontribs)
Cavila (talkcontribs)

Thanks, it works. The idea is, theoretically at first, to concatenate multiple plugins in a single module and then to require that module within the main file of the base module - rather than list and require each plugin file separately. The second option you've given there is interesting, but it looks like I can import the plugins module directly in the main file (of the base module) as long as (a) the plugins module has a dependency on the library module, which is declared in skin/extension.json, and (b) the mw.loader.using pattern illustrated here is used to require the module.

There are other conditions to be satisified but they are more specific to library/plugin conventions I guess - for instance, plugins may expect the library module to be named a particular way (so no custom naming for libraries in skin/extension.json), but that's just noise for now.