Wiki Discussion: SWI-Prolog in the browser using WASM

There is no prolog.pl file under my pack at all. That must be prolog.pl pack handler, right? Any hints?

The current code for swipl-generate uses this function to generate the image. In particular it copies whichever file you point to (in your case le_answer.qlf) into a file in the virtual file system called prolog.pl loads that prolog.pl file and then qsaves the program.

To make this work with multiple files starting from le_answer.pl we will need to extend the logic in this preRun function to make sure that copies all of your imported .pl files. For your specific case you should be able to add something along the lines of

for (const file of ['api.pl', 'drafter.pl', /* rest of file names here */]) {
  module.FS.writeFile(file, fs.readFileSync(path.join(__dirname, file)))
}

to that function.

Let us know how that goes; if it works I would suggest opening up an issue here generalizing that logic to work for all use cases (or for extra points a PR adding the feature :)).

Unfortunately my knowledge of prolog is too limited to know how to correctly detect all the files (and no more) that we need to copy into the virtual file system before building; but if yourself @jan or others can point me in the right direction to help get this working in general for multiple files - then we an investigate doing so.