Using Bun-specific API, would create a hard coded dependency. So that would be a no-go.
Using EMS or CommonJs will not significantly change the performance of the code execution. It will also not reduce the size of the final build.
TiddlyWiki comes with it’s own bundler. The TW --build command does all the packaging that is necessary to get a working single file wiki.
TW uses the exact same code to run server-side and client-side. Since TW is much older than existing code-bundlers including Bun. They will not be able to handle TW modules atm.
You can not trim the tiddlywiki core code.
Trimming “unused” library code is only possible if you know, which code is not needed. In the TW core all the code is needed. With the TW UI all the code is needed - Even if it would not be used by the core-UI itself. Our users may use it.
So removing elements that are not directly used by the core can not be removed, because this will break the backwards compatibility.
There is only 1 thing, which can be done. The TW core code is “packaged” including all the white-space. So it’s easy to debug every wiki. This whitespace makes the code significantly bigger.
So what’s possible is to “uglify” the code. See: Uglify is even uglier. New features. Sourcemapping extravaganza which can make a single file wiki much smaller.
But that’s it.