JS Module in add-on

As Anki’s JS/TS moved to module, would it be possible to have access to it for add-on.
That is, simply, adding type="module" in the bundledScript

It can be done for example by changing the type of WebContent.js" to Union[str, Tuple[str, str]]` where the second string, if present, indicate the type of import. Or any other similar change

I’m not sure what you’re asking Arthur. Could you please explain in more detail what you’re trying to accomplish?

It seems I was wrong about my understanding of module in JS. I beg your pardon.

I wanted to rewrite some add-ons using the module system, so that it’s similar to current anki code and hopefully help me get cleaner add-on code. Saying that some code I wrote when I started add-on developement is ugly code written would be an understatement. Anyway, given what I have read, it seemed to me that if you want to use a module, you add to do

<script src="moduleFile" type="module"></script>

So I wanted to be able to do that in anki.
Now I see that you don’t even have the type parameter for your own “js/editor.js” so I suppose the reason why I failed to use module is not the lack of type. I’m not sure what it is instead but I’ll need to search it.

I still suspect it may be nice to indicate whether something should be interpreted as a module or not, but clearly that is not related to my suggestion

The typescript files are compiled to .js files and then bundled together with their dependencies using a bundler so they can be loaded using normal script tags from a single file.

@dae It would be nice to have a way to easily specify that we want to use type="module" (and maybe other attributes too?) when adding a script via WebContent / the webview_will_set_content hook. Since there is native support for JS modules in the bundled Chromium version and files are being served locally, it seems better to avoid using a bundler if we don’t have another reason to.

Of course we can already do this by modifying web_content.head, but it requires a little more effort.

Anki is gradually moving away from injecting HTML strings in favour of loading HTML files from disk, so I’m not sure how much sense it makes to spend time on this, especially as there’s already a workaround of adding content to head as you said.