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

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?

2 Likes

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!

2 Likes