Adding external JS lib globally to all Plugins and Theme (Components)

AI-generated summary

Adding external JS lib globally to all Plugins and Theme (Components)

The discussion revolves around adding a lightweight logging wrapper, logging JS, to a Discourse instance to improve debugging workflow. The goal is to make the library available throughout all custom plugins, Theme, and Theme Components.

domr109 initially considered importing the JS via register_asset in various plugins, but was concerned about potential multiple imports. They opted for installing a plugin that imports the external JS, making it available via the window object (window.log = log), and having other plugins depend on it.

sam suggested creating a standalone plugin or component to introduce the library, which domr109 acknowledged as the approach they are currently using.

Situation

We want to add this external logging JS lib to our Discourse Instance to improve the debugging workflow by using this lightweight logging wrapper that allows us for example setting up a logLevel via log.setLevel('debug').

This external lib should be available throughout all our custom plugins, Theme and Theme Components we have installed on our App.

Implementation

• Would importing the JS via register_asset in various Plugins import the JS file multiple times?
• Is there an alternative JS lib with similar functionality after Ember deprecated its logging utility in favor of console.log

We currently went down following road to implement it.

  1. Install Plugin which imports external JS and make JS lib available via window object (`window.log = log’)
    • Import JS lib only once imported
    • Other plugins/Theme/Theme Components would depend on that Plugin and things like open source plugins would force users to install both plugins

Does this make sense or would you suggest a different approach?

This feels very decoupled to me… why not make a standalone plugin or component that introduces this and then just make sure you always install it?

Yes, that was actually the solution I mentioned we are using currently. Having 1 plugin that imports the JS and other plugins using it will depend on this plugin to be installed.

Thanks for the reply!