I've figured out a way to make complex plugins split into multiple files, that only require the user to install one main file in the PluginManager. Problem is, my method uses the require() function to get at the non-main files... That breaks browser compatibility.
Is there a way to keep browser compatibility without having to go over each file, turning my plugin into a monolithic one?
I've looked into rollup and Webpack, and despite the tutorials, I don't get how to use them for MV plugins. All my attempts end up with barely-modified versions of the main file that imports the other files :/ How am I supposed to use them?
Short answer: yes, you can do it. Just call PluginManager.loadScript and pass the path to your subsidiary script file. The path is relative to your plugins directory.
As I mentioned, I use the require function to get to the subsidiary scripts. If I'm not mistaken, using loadScript would mean having to go through each script one by one, so that my submodules aren't assigned through the require function.
Maybe you can post a sample of your require usage? I'm not quite seeing why replacing it with loadScript would not work, but perhaps I'm missing something. At the very least I imagine you could use loadScript to somehow implement something similar to require.
Ah, okay, I get the basic problem here.
For web-compatible loading, I believe the options are basically just PluginManager.loadScript or XHR (what DataManager.loadDataFile does, but the details would be a little different for your use case). I'm not quite sure about loadScript, but XHR is inherently asynchronous, so while I'm certain you could get something that works, it wouldn't be a simple drop-in replacement for require - you'd need to restructure your code to account for require returning the equivalent of a Promise.
Perhaps the most straightforward way to do this would be to pre-load every possible module into a table of loaded modules and defer your entire plugin initialization (or at least, anything that depends on a module) until they have all loaded, though this would mean your plugin's position in the plugin list no longer means anything (probably).
In summary: I think there exists a solution that doesn't involve a compilation step to merge the files into a single monolithic blob, but probably not without some restructuring of how you do things.