I noticed that the js files added using
register_asset via plugins are passed as a string to
The problem with eval is, it doesn’t add the object to the global scope as discussed here.
To be specific, I was trying to use
https://github.com/muaz-khan/RecordRTC/blob/master/RecordRTC.js in a plugin but the functions aren’t accessible in the ember files.
The workaround for this is to process the file with webpack, using
Many of the libraries are processed this way which seems to work out of the box.
Now I’m not an expert on these things, but just wondering whether it makes sense for discourse to add the registered assets to the global scope.
Note: Apologies if some of this sounds silly. I didn’t expect to fiddle with webpack to get js libraries working with discourse which motivated me to post this writeup.