zadam / trilium

Build your personal knowledge base with Trilium Notes
GNU Affero General Public License v3.0
27.2k stars 1.9k forks source link

(Feature request) Sharing Javascript code between plugins #4467

Closed BeatLink closed 11 months ago

BeatLink commented 11 months ago

Describe feature

Hi, I'm currently working on a recurrence plugin for trilium and there's a recurrence class that is shared between a widget and a few scripts. Right now i have to copy and paste the class to each script and the widget. Is there a way to share it without duplication?

Additional Information

No response

henrikx commented 11 months ago

https://github.com/zadam/trilium/discussions/4266

zadam commented 11 months ago

The canonical way to share e.g. functions between different widgets is by putting them into a separate note and cloning them under scripts/widgets where they are meant to be used.

This is showcased in the demo document in the Statistics - find "renderPieChart" note and see how it is cloned to 2 different places in the tree:

In the screenshot you can also see that it declared CommonJS module.exports

This module is then automatically imported into notes into which renderPieChart is cloned:

BeatLink commented 11 months ago

Thanks!