Existing JS module import into ES6 plugin

I’m writing a markdown plugin which needs an external JS for server side code. How to import the module properly so it will be detected by mini_racer. I can either import JS module (as git submodule) or already compiled min.js.

If I just do register_asset ‘file.js’, :server_side it works in browser, but not when I try to rebuild post HTML.

This is an example of plugin that modifies post cooking:

https://github.com/discourse/discourse/blob/master/plugins/poll/assets/javascripts/lib/discourse-markdown/poll.js.es6

4 Likes

Thank you for your example. Here you included full function inline. Is there a way to “require” it to have a cleaner plugin?

1 Like

If I copy the (un)minified code of the library directly to plugin ES6 file, it fails.