To ship a JavaScript library with a Discourse plugin, it is recommended to add the library to the assets folder and register it in the plugin.rb file. Overgrow initially asked about this and received guidance from Falco and later confirmed that placing the library in the asset folder and registering it worked.
However, when trying to load a complex library with submodules, issues may arise. DawnPaladin encountered problems loading a library with multiple dependencies and was advised by joffreyjaffeux to examine the code of the discourse-algolia plugin for reference.
DawnPaladin then asked about adding an NPM module to a Discourse plugin, specifically dealing with a library that relies on submodules. joffreyjaffeux suggested using a fully packaged solution.
But I’d prefer storing library locally. Normally I’d use vendor.js to include it and have it loaded before the plugin code, but this approach needs hacking with the Discourse core.. So what is recommended way and where to add external js library to plugin? Is there some convention? Thx.
Thanks… In the assets folder will it be loaded automatically or do I need to take care of asynchronous load as quoted in previous post? I need to load library before running plugin code.
I asked a similar question a few days ago (Existing JS module import into ES6 plugin). The problem I have is, that I want it included server side and I have no idea on which path I should require it in ES6 modules.
assets/javascripts/discourse-markdown/argdown.js.es6 で import { argdown } from "argdown-core.js" と記述しています。
上記のバリエーションをいろいろ試しましたが、常に Uncaught Error: Could not find module argdown-core.js imported from discourse/plugins/Argdown/discourse-markdown/argdown というエラーが発生します。