Importing text files the same way in node (commandline) or webpack (browser) code should be possible but its all a bit confusing with the new ES module system so I had to put my thinking cap on and read through https://nodejs.org/api/module.html#loadurl-context-nextload to work out how exactly to do it.
Seems you need a couple of files to preload the module hooks, one to be imported on the command line so it gets run before anything else tries to import anything and then another one to contain the actual module hooks. I tried using one file, which kinda works but ends up registers the hooks twice which is not good.
I've also synced the pattern test with the one used by raw-loader in webpack.config.cjs so node and webpack should always consider the same files as text.
All the new code is in this commit https://github.com/notshi/seance/commit/e7a541356449c2eb924c98e8f244e21ac46ca73a and you can also see how the imports have replaced readfile hacks.